Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Read a list of files into an array

by cengineer (Pilgrim)
on Jun 22, 2007 at 15:43 UTC ( [id://622825]=note: print w/replies, xml ) Need Help??


in reply to Read a list of files into an array

This sub returns an array ref. You could also opt not to use the sub to access the array directly, instead.
#!/usr/bin/perl use strict; use warnings; my $somedirectory = "/root/dir/"; my $files = dirlist($someDirectory); foreach my $fileInDirectory (@$files) { dosomething($fileInDirectory); } sub dirlist { my $dir = shift; my @filelist; opendir(DIR, $dir) or die "can't opendir $dir: $!"; while (defined(my $file = readdir(DIR))) { # Skip "." and ".." next if ($file =~ /^\.\.?$/); push(@filelist, $file); } closedir(DIR); return \@filelist; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2024-03-28 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found