Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: To glob or not to glob

by choroba (Archbishop)
on Jan 08, 2018 at 10:43 UTC ( #1206895=note: print w/replies, xml ) Need Help??


in reply to To glob or not to glob

Another potential danger of glob is its usage in scalar context. It should return the matches one by one, but the iterator is assigned to the place where glob is used and isn't reset when a new parameter is supplied to it:
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; open my $fh, '>', $_ for my @files = qw( a1 a2 b1 b2 ); for my $mask ('a*', 'b*') { while (my $f = glob $mask) { say $f; last } } unlink @files;

Yes, this returns no strings starting with b.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-08-20 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?