SPUG: Filehandes -- slurping up the files in \folder\*.htm?

Stuart Poulin stuart_poulin at yahoo.com
Fri Feb 11 13:01:49 CST 2000


--- Dean Hudson <dean at ero.com> wrote:
> On Wed, 9 Feb 2000, Greg Mushen wrote:
> 
> > # This will open the directory
> > opendir(DIR, "<your-dir>") or die "Can't open dir: $!\n";
> >  
> > # This will go through each file in that directory.
> > while(defined ($file = readdir(DIR))) {
> >             open(FILE, "$file");
> >             do whatever else here
> > }
> 
> Or if you're feeling slightly more "fast & loose":
> 
> my $dir = "/your/dir/here";
> while ( my $file = <$dir/*> ) {
>     # process file
> }
> 

I just wanted to throw a little caution to this.  This last example example
uses file globbing.  Globbing is not built into perl.   This on Unix means
calling csh, or tcsh depending on how perl is built, and on NT it calls
perlglob.exe.  These don't always glob the same.  And csh shell can throw a
error about the file list being too long.  Plus, it's actually slower since
perl has to call an external program.  Readdir is the safest way to go but I
often first reach for globbing. 
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list