Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by doubledecker (Scribe)
on Jul 11, 2012 at 13:19 UTC ( #981113=note: print w/replies, xml ) Need Help??


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

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

  • Comment on Re^2: get list of files matching part of file name

Replies are listed 'Best First'.
Re^3: get list of files matching part of file name
by Athanasius (Chancellor) on Jul 11, 2012 at 13:29 UTC

    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://981113]
help
Chatterbox?
[ovedpo15]: If I use "unless(opendir(my $dir, $test_dir))" why does it give me error "Global symbol "$dir" requires explicit package name at" if I used "my"? If I use my $dir before the opendir it works.. but why?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-04-22 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?