Despite your updates, you still haven't shown us the code you are really running so I'm still not entirely sure what you are trying to accomplish but this should give you a push in the right direction.
#!/bin/env perl use strict; use warnings; my @day_of_year = (4257,4257,4258,4259); # If @day_of_year only contains the days then there is no reason for m +atching for my $day_of_year (@day_of_year) { print "looking for things in $day_of_year folder /home/myfiles/day_o +f_year/$day_of_year/*/desired_file.txt\n"; # there may be multiple directories containing desired_file.txt my @desired_paths = glob('/home/myfiles/day_of_year/'.$day_of_year.' +/*/desired_file.txt'); for my $info_desired_filepath (@desired_paths) { print "$info_desired_filepath \t\t is the file name \n\n"; <STDIN>; open (my $info_FH, '<', $info_desired_filepath) or die "cannot open $info_desired_filepath..........\n\n"; print "found a file!!!!!!\n"; chomp(my @lines = <$info_FH>); close($info_FH); print "lines:\n"; print "$_\n" for @lines; # yep, we actually read the data } } __DATA__ Directory structure: myfiles/ day_of_year/ |-- 4257 | |-- a | | `-- desired_file.txt | |-- b | | `-- desired_file.txt | `-- c | `-- desired_file.txt |-- 4258 | |-- a | | `-- desired_file.txt | `-- c | `-- desired_file.txt `-- 4259 `-- c `-- desired_file.txt Output: skimming for the day of year number: 4257 looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/des +ired_file.txt /home/myfiles/day_of_year/4257/a/desired_file.txt is th +e file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/b/desired_file.txt is th +e file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/c/desired_file.txt is th +e file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4257 looking for things in 4257 folder /home/myfiles/day_of_year/4257/*/des +ired_file.txt /home/myfiles/day_of_year/4257/a/desired_file.txt is th +e file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/b/desired_file.txt is th +e file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4257/c/desired_file.txt is th +e file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4258 looking for things in 4258 folder /home/myfiles/day_of_year/4258/*/des +ired_file.txt /home/myfiles/day_of_year/4258/a/desired_file.txt is th +e file name found a file!!!!!! lines: data /home/myfiles/day_of_year/4258/c/desired_file.txt is th +e file name found a file!!!!!! lines: data bogus data skimming for the day of year number: 4259 looking for things in 4259 folder /home/myfiles/day_of_year/4259/*/des +ired_file.txt /home/myfiles/day_of_year/4259/c/desired_file.txt is th +e file name found a file!!!!!! lines: data
Updated: Added directory structure and output from my test run.
In reply to Re: Globbing for file in an unkown directory path only works first time in foreach loop?
by Mr. Muskrat
in thread Globbing for file in an unkown directory path only works first time in foreach loop?
by MarsRover
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |