http://qs1969.pair.com?node_id=1206895


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;

($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,