Question

I'm trying to do something that seems fairly simply but I cannot figure out for the life of me how to get what I need.

I have a variable called $scene, and I want to get an array of filenames that belong to the scene variable so that I can loop through them and "do stuff". Some files have an LE7 prefix, others LT5 and LT4. Additionally, there are several files that belong to a scene, each with a unique date. I'm very new to perl (as in just started today) and I can't seem to grasp the whole strings/escaping/variable deal.

Here's the first way I tried:

#!/usr/bin/perl -w

use autodie;
use strict;
use warnings;
use File::Glob ':glob';

my $inpath = "indata/gz";

open(LIST, "desktop/migrate_list.txt");

while (my $scene = <LIST>){
    chomp $scene;
    my @gzfiles=glob("$inpath/L??$scene*.gz");

    foreach my $gzfile (@gzfiles) {
        # do stuff....

    }
}
close LIST;

I could go into detail about the different things I've tried and results I've gotten but basically my methods have been very crude and results a bunch of senseless crap (most importantly--the glob array always turns up empty).

Obviously, I'm missing how to incorporate wildcards and variables into a string/command call. I've tried a lot of things but I'm thinking/hoping someone knows a solution off the top of their head because I have no idea.

To be clear on what I'm looking for, here's an example. Say $scene = "011099". Then the array could include the following files:

LE70110992001365-SC28491244.tar.gz,     LT40110991990001-SC9793793477.tar.gz,
LT40110992010099-SC983698346923.tar.gz, LT50110992002365-SC6938693863.tar.gz,
LE70110991992001-SC936983693.tar.gz, ...

Any help is appreciated. Thanks!

Was it helpful?

Solution

Converting debugging in comments to answer:

Use this:

use Data::Dumper; 
$Data::Dumper::Useqq = 1; 
chomp(my @scenes = <LIST>); 
print Dumper \@scenes; 

And see if you have the lines you think you have in the file. It looks like your problem is that you have space in your file somehow, which would break the glob.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top