Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Adding Files in a directory to an array

by davorg (Chancellor)
on Oct 09, 2001 at 13:21 UTC ( #117674=note: print w/ replies, xml ) Need Help??


in reply to Adding Files in a directory to an array

Yeah, you can't do that, because Perl gets confused between the globbing operator (<*.txt>) and the file input operator (<FILE>).

The way to do it it to use the glob function instead.

$searchcontacts = "cd32/*.cd"; @allcontacts = glob($searchcontacts);
--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


Comment on Re: Adding Files in a directory to an array
Download Code
Re:{2} Adding Files in a directory to an array
by jeroenes (Priest) on Oct 09, 2001 at 15:10 UTC
    Not exactly.

    While it is better (and I mean really, really better) to use the functional glob, you still can force perl to interpolate variables. Actually, only filehandles and simple scalars are not interpolated (see perlop). So these:

    @dir=<$hash{$key}>; @dir=<$array[0]>; @dir=<$object->method>; @dir=<${foo}>; # and even @dir=<$structure{'filehandle'}>;
    are interpreted as globs. Note that this is a caveat in the last case! Since you probably want the <> to do a readline in the last case, people really need to be aware that nested structures are always globbed. Only simple, straightforward variables like $foo result in readlines.

    Jeroen
    "We are not alone"(FZ)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2015-07-01 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (6 votes), past polls