Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Dumb or Cursed?

by BazB (Priest)
on May 23, 2002 at 18:59 UTC ( #168875=note: print w/replies, xml ) Need Help??


in reply to Problems with -filetest on readdir results

#!/usr/bin/perl use strict; use warnings; my $path="/foo/bar/"; opendir (DIR, $path) or die "Could not open directory: $!"; @files = readdir(DIR); foreach my $file (@files) { print "$file\n"; }
Your foreach loop was incorrect. Use of strict and warnings also helps spot errors.
You could also replace the foreach loop with a map statement:
print map {$_ = "$_\n";} @files;
Cheers!

BazB.

Update: I ignored the -d test, and obviously don't know my foreach loop from my elbow. Oops. ides++ and boo_radley++

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-05-24 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?