Home: Perl Programming Help: Beginner:
$MATCH not working like $`



Cupidvogel
Novice

May 4, 2012, 5:30 AM


Views: 1342
$MATCH not working like $`

Hi, as per the Perlvar manpage, the $PREMATCH variable (alongwith @- and @+ arrays) was meant to do the same thing as $` without the performance overload of the latter. However, when I try the following code:


Code
$a = "abc123dfv"; 
if ($a =~ m/\d+/) {
print "Yep: $PREMATCH \n";
}


Nothing gets printed after Yep:, whereas if I run this:


Code
$a = "abc123dfv"; 
if ($a =~ m/\d+/) {
print "Yep: $` \n";
}


I get the usual result: Yep: abc. Can anybody explain it?


FishMonger
Veteran / Moderator

May 4, 2012, 6:15 AM


Views: 1324
Re: [Cupidvogel] $MATCH not working like $`

You question was answered on devshed.
http://forums.devshed.com/perl-programming-6/match-not-working-like-903193.html