just that partial snippet looks ok .. two general ideas:
You can always put next unless -f $job; in the foreach -- that will exclude directories (see -X).
A File::Find::Rule approach:
my @files = File::Find::Rule->file()
->name(qr/^.{36}\.txt$/)
->maxdepth(1)
->in("G:/Perl_program/Input");
my @tags = map { /(.{36})\.txt$/ ? $1 : undef } @files;
| [reply] [d/l] [select] |
>perl -le "print 0 + map undef, 1..2
2
>perl -le "print 0 + map { () } 1..2
0
| [reply] [d/l] [select] |
yeah, good point. i actually almost wrote it as my @tags = grep {defined $_} map { ... } @files; (though i like the ? $1 : () much better).. left it out because, in theory, it should never not match, and if it does fail to match, perhaps (no clue if he does or not) OP wants to trap those cases ...
foreach my $tag (@tags){
die "found a blank" unless defined $tag;
....
}
(though i guess in that case you can't, very easily, tie the failing tag back to an offending file ... hm.) | [reply] [d/l] [select] |
Use -d to check if it's a dir. Better yet, use -f to check if it's a normal file.
my $path = File::Spec->catdir($dir, $file);
next unless -f $path;
| [reply] [d/l] [select] |
Considering it's incomplete code calling a non-standard routine which does who-knows-what, you're pretty much going to get no useful answers.
Well, you'll get useful answers like the above pointing you at File::Find::Rule; but you'll ignore them and blindly rage on and post 3 more all but identical questions trying to figure out why what you've not shown us isn't meeting your unspecified personal definition of "working"-ness.
And despite the fact that you'll get several more people replying to each of them pointing you at How (Not) To Ask A Question YET AGAIN you'll still persist in posting poorly formulated, incomplete questions.
If only PM had /ignore for SoPW . . .
| [reply] |
when there is a folder within the directory
Consider the following:
| hand waving on how we got here...
|
opendir(DIR,".") or die $!;
while(my $name=readdir(DIR)){
next if -d $name; # takes care of . and .. as well
| do something with file here...
}
Certainly not the only solution.. but one of...
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
| [reply] [d/l] |