[Mastering-perl] Why doesn't this work?
Andy Armstrong
andy at hexten.net
Fri Dec 15 13:12:01 EST 2006
From Ch1:
# Doesn't actually work - the list assignment to $word seems to kill
pos($_)
$_ = "Just another Perl hacker,";
my $pos = pos( $_ ); # same as pos()
print "I'm at position $pos\n"; # -1
my( $word ) = /(Just)/g;
$pos = pos();
print "[$word] ends at position $pos\n"; # 4
# This works fine
$_ = "Just another Perl hacker,";
my $pos = pos( $_ ); # same as pos()
print "I'm at position $pos\n"; # undef
/(Just)/g;
$pos = pos();
print "[$1] ends at position $pos\n"; # 4
Tested on 5.8.8 Ubuntu and 5.8.6 Mac OS X.
--
Andy Armstrong, hexten.net
More information about the Mastering-perl
mailing list