Re: [MacPerl] $PREMATCH Question
[email protected] (Matthew Fischer) Wed, 3 Feb 2016 07:55:58 -0500
| Newsgroups | perl.macperl |
|---|---|
| Message-ID | <CA+hBnT49A-Rtwp5jXs041PrW3YYQ3cjYFjukRv42YdcNexYnvg@mail.gmail.com> |
--001a11372b2ae16396052add24bb
Content-Type: text/plain; charset=UTF-8
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 <[email protected]>
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
--001a11372b2ae16396052add24bb
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>From=C2=A0<a href=3D"http://perldoc.perl.org/perlrere=
f.html">http://perldoc.perl.org/perlreref.html</a> -</div><div><br></div><d=
iv>p =C2=A0Preserve a copy of the matched string -</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} w=
ill be defined.</div><div><br></div><div><div>fishbookAirMobile:~ fishman$ =
echo alphabet | perl -e '$_=3D<STDIN>; if (m/pha/p){print ${^PREM=
ATCH}, "\n"}'</div><div>al</div></div><div><br></div></div><d=
iv class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Tue, Feb 2, 2016=
at 8:59 PM, Jonathan Levi via macperl <span dir=3D"ltr"><<a href=3D"mai=
lto:[email protected]" target=3D"_blank">[email protected]</a>></span> wro=
te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-=
left:1px #ccc solid;padding-left:1ex"><font color=3D"black" size=3D"2" face=
=3D"Arial, Helvetica, sans-serif"><font size=3D"2">Can someone explain why =
the following:<br>
<br>
<font face=3D"Courier New, Courier, mono">echo alphabet | perl -e '$_=
=3D<STDIN>; if (m/pha/){print $PREMATCH, "\n"}'</font><=
br>
<br>
yields "" instead of "al", as I expected?<span class=3D=
"HOEnZb"><font color=3D"#888888"><br>
<br>
Jonathan<br>
</font></span></font>
</font></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div =
class=3D"gmail_signature"><div dir=3D"ltr">Matthew Fischer<br>Director of T=
echnology Services<br>Connecticut Association of Schools<br>Connecticut Int=
erscholastic Athletic Conference<br>W: 203.250.1111 || M: 203.314.9915<div>=
<a href=3D"http://casciac.org" target=3D"_blank">casciac.org</a>=C2=A0||=C2=
=A0<a href=3D"http://cas.casciac.org" target=3D"_blank">cas.casciac.org</a>=
||=C2=A0<a href=3D"http://ciacsports.com" target=3D"_blank">ciacsports.com=
</a></div></div></div>
</div>
--001a11372b2ae16396052add24bb--