Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: get list of files matching part of file name

by Athanasius (Abbot)
on Jul 11, 2012 at 13:29 UTC ( #981116=note: print w/ replies, xml ) Need Help??


in reply to Re^2: get list of files matching part of file name
in thread get list of files matching part of file name

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


Comment on Re^3: get list of files matching part of file name
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2015-07-31 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls