While reading 'mastering perl', I run into @- and @+ for the first time.
Trying to understand what's going on, I ran the code from the book, but

$-[1] and $+[1] shoudln't match only the first match? (in this case,
shoudln't it be, 7 to 8 ?, instead of 7 to 9 ?)

--code--
#!/usr/bin/perl
$alphabet = "abcdefghijklmnopqrstuvwxyz";
$alphabet =~ /(hi).*(stu)/;

print "\$alphabet is $alphabet\n";
print "We are looking from h to u\n";
print "match is \$& , which is $&\n";
print "\$` is $`\n";
print "\$' is $'\n";
print "\$1 is $1\n";
print "\$2 is $2\n";


print "The entire match began at $-[0] and ended at $+[0]\n";
print "The first match began at $-[1] and ended at $+[1]\n";
print "The second match began at $-[2] and ended at $+[2]\n";

--running them--
./regex-3.pl
$alphabet is abcdefghijklmnopqrstuvwxyz
We are looking from h to u
match is $& , which is hijklmnopqrstu
$` is abcdefg
$' is vwxyz
$1 is hi
$2 is stu
The entire match began at 7 and ended at 21
The first match began at 7 and ended at 9
The second match began at 18 and ended at 21


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to