[Sderby] PERL

Andrew White sderby at mailman.lug.org.uk
Fri Dec 27 15:49:00 2002


> Does anyone know anything about PERL?  I'm trying to capture the listing
> of a directory and then assign each file name to a variable for testing.
>  I've got as far as
>
> $line=`ls`
>
> Now I want to set up a loop to assign the first file to a variable, test
> it, then the second, then third, etc.
>
> Sorry if this isn't too clear, I can't find a clear way to explain it!


for $f (<./*>) {
  if (-f $f ) { print "$f \n";}
}

the first line "<./*>" is a file glob, which basically reads everthing in the
current directory, expanded as the shell would, and loops through it holding
the current value in $f.

the if (-f...) line checks if the current item is actually a file. If it
is, print it..

anyway, that should be enough to get you going

regards,

Andy