[Sderby] PERL

David Jolley sderby at mailman.lug.org.uk
Fri Dec 27 14:26:00 2002


* hemstock@tiscali.co.uk (hemstock@tiscali.co.uk) wrote:
> All,
> 
> 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.
> 
What do you then need to do to the filenames in the variables - it may
be the case that what you actually need to achieve is best achieved in
sh script, and judicious use of xargs.

Failing that, to assign all the filenames to a list use:

$a = (`ls`);

Then;

print "$a";

will print them all out to confirm it worked.  Or, more accurately, it
worked for me :)

You should then be able to use the perl list iteration constructs to
go through each element in turn.

> Sorry if this isn't too clear, I can't find a clear way to explain it!
> 
Hopefully this is what you wanted...

Cheers,

Dave.

-- 
Lord of the Rings (abridged):
        Some guys take a long holiday to throw a ring in a volcano.