2007/10/11, Jim <[EMAIL PROTECTED]>: > > Hi Everyone, > > I am trying to match file & subdir names from a back tic generated list. > I never find anything and there are files in the directory with a correct > name. > but if i make up a list to use as filenames > it works as i expect ... any insight greatly appreciated > > thanks > Jim > > #!/usr/bin/perl > > use strict; > use warnings; > > my @files = qw (filename1 filename2 filename3 filename4); > #my @dir = qw (file filenaml filename filename2); > my @dir = `dir`; > > foreach my $file (@files) > { > foreach my $line (@dir) > { > if ($file =~ m/$line/) > { > print "\nfound one\n"; > } > print "file - $file "; > print "line - $line\n"; > } > } > > Since you placed #!/usr/bin/perl at the head line, I assume you are on the *nix. not familiar with *nix, but I guess if you need this : foreach my $line ( @dir ) { chomp $line; .... other statements ... } because I think there's a "\n" or "\r\n" tailing in each elements in @dir and you'll need to cut it off.
However, if you are on Win, `dir` will gather another whole story list. you can try to : print $line ; to see what you have got from `dir` One thing more, you do not want to compare if there's same file by regex, you 'll need if ( $file eq $line ) { } Regards =) Panda-X