Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Extract information from several files in directory

by wazat (Monk)
on Nov 29, 2020 at 18:32 UTC ( [id://11124371]=note: print w/replies, xml ) Need Help??


in reply to Extract information from several files in directory

One thing to be aware of is that readdir() returns file names without the directory part. If using readdir() you will need to prepend the file names with the directory part of the file path in order to open it for reading.

You could just build the path yourself, which is not necessarily portable.

my $path = "Filer/$filename";

or you could use File::Spec->catfile() for portability

use File::Spec; my $path = File::Spec->catfile('Filer', $filename");

This is an old fashioned approach.

If you use glob() it will return file paths. Then again for portability code>File::Spec->catfile()</code> could be used to build the argument to glob().

As others have pointed out, using Path::Tiny simple. It is a more modern approach. For example

my @paths = path("Filer")->children( qr/\.txt\z/ ); # now do something with each element of @paths

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found