>From http://perldoc.perl.org/perlreref.html -

p  Preserve a copy of the matched string -
              ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be defined.

fishbookAirMobile:~ fishman$ echo alphabet | perl -e '$_=<STDIN>; if
(m/pha/p){print ${^PREMATCH}, "\n"}'
al


On Tue, Feb 2, 2016 at 8:59 PM, Jonathan Levi via macperl <macperl@perl.org>
wrote:

> Can someone explain why the following:
>
> echo alphabet | perl -e '$_=<STDIN>; if (m/pha/){print $PREMATCH, "\n"}'
>
> yields "" instead of "al", as I expected?
>
> Jonathan
>



-- 
Matthew Fischer
Director of Technology Services
Connecticut Association of Schools
Connecticut Interscholastic Athletic Conference
W: 203.250.1111 || M: 203.314.9915
casciac.org || cas.casciac.org || ciacsports.com

Reply via email to