MarsRover has asked for the wisdom of the Perl Monks concerning the following question:
All,
I have a file named... uhh... lets call it desired_file.txt and there is a file with this same name in a directory path that is specific to the day of year it was created on. (yes i know this is a "hill-billy database i'm working with but it's what i'm stuck with so i have to deal with it......)
i.e. the path to a few of these are:
/home/myfiles/day_of_year/255/data/JPF_374362/desired_file.txt
/home/myfiles/day_of_year/256/data/EJF_264827/desired_file.txt
/home/myfiles/day_of_year/257/data/FFE_387392/desired_file.txt
...
/home/myfiles/day_of_year/###/data/desired_file.txt
respectively for days of year 255, 256, 257.
I have a foreach loop that is accessing an array where each element of that array contains the number for the day of year it wishes to access data for (and replaces ### in the path above to find the desired_file.txt for that day).
in the foreach, my script pulls the day of year from the array element in question, then attempts to open the "desired_file.txt" in the path associated with that day of year. the code is something like:
EDIT: putting in the actual code
<p>Okay, [actual code]:</p> <code> #!/tps/bin/perl -s my @day_of_year = (4257,4257,4258,4259); foreach (@day_of_year) { print"\nskimming for the day of year number:\n"; if ($_ =~ /(\d{4})/){ $day_of_year = $1; print "looking for things in $day folder /home/myfiles +/day_of_year/$day_of_year/*/desired_file.txt\n"; my $info_desired_filepath = glob('/home/myfiles/day_of +_year/'.$day_of_year.'/*/desired_file.txt'); print "$info_desired_filepath \t\t is the file name \n +\n"; <STDIN>; open ($info_FH, '<', $info_desired_filepath) or die "cannot open $info_desired_filepath.... +......\n\n"; print "found a file!!!!!!\n"; chomp(@lines = <$info_FH>); close($info_FH); } }
skimming for the day of year number:
looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/desired_file.txt
/home/myfiles/day_of_year/4257/JKY_63521/desired_file.txt is the file name
found a file!!!!!!
skimming for the day of year number:
looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/desired_file.txt is the file name
cannot open ..........so what ends up happening is, the first time through, the script does exactly what i want. it find the file, opens it, munches on it and then goes back to the foreach for the next day of year value in the array. Thing is, the next time through, it die's saying it can't find the file.
Even if the first and second elements of the @days_of_year_array are THE SAME DAY OF YEAR, it works the first time but then the second time the print statement after the glob shows that $info_desired_filepath is empty.....
oh, and one last thing, i am using v5.8.3 built for sun4-solaris
HALP!
thanks folks
|
|---|