in reply to thanks, i'm new. rtfm right? :)

Don't use awk. Instead, try this.

opendir(DIR,"."); @d=readdir(DIR); closedir(DIR); foreach $j (@d) { $_=$j; $template=/^.*\.[^.]+/ if(/$count/); }
Error checking is left to the exersize of the student, as well as accomidating for two or more hits of /$count/. Besides, the less you spawn a shell, the better (unless it's a quick hack);

--
$Stalag99{"URL"}="http://stalag99.keenspace.com";

Replies are listed 'Best First'.
RE: Re: thanks
by the_slycer (Chaplain) on Oct 25, 2000 at 17:30 UTC
    The assignment of $_ to $j seems redundant to me. Just write it like this:
    foreach (@d) { $template=/^.*\.[^.]+/ if(/$count/); }
    $_ is already filled with whatever is in @d...
Don't use opendir
by tedv (Pilgrim) on Oct 25, 2000 at 21:28 UTC
    You can parse the files in the directory with a structure like this, instead of using opendir/readdir/closedir:
    my @files = (); foreach (<*$count*>) { s/\.[^.]*$//; push @files, $_; }

    Not sure what you needed to do with the files, but you might do that inside the loop as well. I'm not sure exactly how <*> works internally, but it's definitly better than doing a system() call that relies on ls, awk, and grep (even if those are fine tools). I find it cool, yet strangely disturbing, that you can interpolate the variable $count into the <...> directory listing.

    -Ted
      <*> (file globbing) used to spawn a csh process (and used to do some other horrible thing on Windows), but now (as of 5.6?) uses File::Glob. I still avoid it, because (open|read|close)dir with grep provides better file and pattern matching capabilities. And maybe I just find the syntax ambiguous (I confuse it with reading lines of a filehandle), which is maybe just my own prejudice. I'm curious as to what others think of file globbing vs. readdir...
        Absolutely. I was seriously burned once on an older Perl with scripts that used globbing which began returning nothing when the directory got too many files. *THAT* was a fun one to debug, and I am not a great fan of rewriting production jobs on the fly. :-(

        Even with File::Glob I would avoid globbing if there was going to be any possibilities of filenames with spaces or wildcards in them. The semantics of readdir etc are safe with meta-characters. The sematics of globbing are very troublesome.