Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How do I read all the file names of a directory into an array?

by eg (Friar)
on Dec 10, 2000 at 13:37 UTC ( [id://45933]=note: print w/replies, xml ) Need Help??


in reply to How do I read all the file names of a directory into an array?

Use backticks (`) to execute a shell command and capture its output (see the perlop manpage):

my @filename = split("\n", `ls`); my $total = scalar(@filename);

This would replace everything after the line "use strict;" and before "$error = ...".

Note you can also replace your for-loop with a foreach which would mean you wouldn't need $total any longer. See perlsyn.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45933]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found