in reply to Reading specific files from a directory

you could use:
#!/usr/bin/perl -w use strict; my $somedir = "/home/me/lala"; my $file; opendir (DIR, $somedir); while ($file = readdir DIR) { print "$file\n"; if ($file =~ /^example\.\d+\.txt$/) { print " -- FOUND example: $file\n"; } }
I'm not whether my code is any faster or more optimal than yours; I'll leave that for monks greater than I =) BTW, I'm not sure if it's a typo but:
open (DIR, $somedir);
should be:
opendir (DIR, $somedir);

Replies are listed 'Best First'.
Re: Re: Reading specific files from a directory
by Lexicon (Chaplain) on Mar 12, 2001 at 11:06 UTC
    Somedays it just doesn't pay to post code (it almost always pays to write code thankfully.) Yeah, the opendir is a typo here that I made while simplifying the problem down for PM. And uh....I have no excuse for why I regenerated my file name. In a hurry combining code and not thinking hard enough. I'm gonna go back to my cave and write HTML now.

    -Lexicon