Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: get list of files matching part of file name

by RichardK (Priest)
on Jul 11, 2012 at 12:37 UTC ( #981106=note: print w/ replies, xml ) Need Help??


in reply to get list of files matching part of file name

you didn't say what you expect your code to do, so it difficult to offer any useful suggestions, other than glob('sample*.txt')

Maybe my @files = glob (".* *") doesn't do what you think it does?

see glob


Comment on Re: get list of files matching part of file name
Select or Download Code
Re^2: get list of files matching part of file name
by doubledecker (Scribe) on Jul 11, 2012 at 13:19 UTC

    I used glob to list all the files in my current directory and using those list of files i'm trying to find out matching files in other directory

      A couple of points:

      (1) In the foreach loop, $file contains a filename together with its path and extension. To extract just the name part, you need something like:

      (my $basename = fileparse($file)) =~ s/ \. .* $ //x;

      which uses the fileparse function from File::Basename to extract the filename, then removes the extension (if any).

      (2) print Dumper(@matches); will print each match on a separate line. You would probably be better off with something like this:

      printf "'%s' matches: %s\n", $basename, join(', ', @matches);

      HTH,

      Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981106]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-08-22 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls