Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Use of special character "*" to retrieve the contents

by shmem (Chancellor)
on Jun 07, 2017 at 13:05 UTC ( [id://1192269]=note: print w/replies, xml ) Need Help??


in reply to Use of special character "*" to retrieve the contents

See glob.

for (glob "$var1/$var2/$var3/*.ksh") { print "$_\n"; }

For portability, it is better to use File::Spec:

use File::Spec; ... my $pat = File::Spec->catfile($var1,$var2,$var3,'*.ksh'); for(glob $pat) { print "$_\n"; }
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Use of special character "*" to retrieve the contents (updated)
by haukex (Archbishop) on Jun 07, 2017 at 14:06 UTC

    When I see the use of glob I often feel compelled to point out that it has its caveats, such as how it handles whitespace in its argument, and also that it does not list filenames beginning with a dot by default (which might be surprising to users when compared to readdir or File::Find). A thorough read of glob and File::Glob, which implements the former, is recommended.

    Update: While File::Spec is often very good advice, I looked into this a bit, and note that the File::Glob doc discusses how on Win32, backslashes can interfere with escaping, and that forward slashes are recommended.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-23 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found