Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: testing files for valid content

by almut (Canon)
on Apr 23, 2009 at 17:01 UTC ( [id://759589]=note: print w/replies, xml ) Need Help??


in reply to testing files for valid content

my @files=grep {$_ ne '.' && $_ ne '..'} @files=readdir(DIR);

Not directly related to your question, but I've seen this construct a couple of times now in code you posted, so I thought it's maybe worth commenting on... before it becomes a habit :)

The 'normal' way to write this would be

my @files=grep {$_ ne '.' && $_ ne '..'} readdir(DIR);

No need to assign the list of files to an intermediate array — which is also a different (i.e. package) variable from the first lexical my @files, BTW.

Has anyone ever suggested to try use strict?  ;)

Replies are listed 'Best First'.
Re^2: testing files for valid content
by toolic (Bishop) on Apr 23, 2009 at 20:30 UTC
    Good advice.

    And if files are all that are needed (no directories), why not filter out all directories, not just those 2 special ones?

    my @files = grep {-f "$dir/$_"} readdir(DIR);

    where $dir is the directory path which DIR points to.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found