develooper Front page | perl.macperl | Postings from February 2016

Re: [MacPerl] $PREMATCH Question

Thread Previous
From:
Matthew Fischer
Date:
February 3, 2016 14:57
Subject:
Re: [MacPerl] $PREMATCH Question
Message ID:
CA+hBnT49A-Rtwp5jXs041PrW3YYQ3cjYFjukRv42YdcNexYnvg@mail.gmail.com
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

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About