Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Read a list of files into an array

by cengineer (Pilgrim)
on Jun 22, 2007 at 15:43 UTC ( #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 browsing the Monastery: (3)
As of 2023-12-06 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (29 votes). Check out past polls.

    Notices?