[32956] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4232 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 6 09:09:14 2014

Date: Fri, 6 Jun 2014 06:09:02 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 6 Jun 2014     Volume: 11 Number: 4232

Today's topics:
    Re: Delicious Perl bug <derykus@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 05 Jun 2014 23:20:43 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Delicious Perl bug
Message-Id: <lmrmkf$25c$1@speranza.aioe.org>

On 6/1/2014 5:42 AM, Peter J. Holzer wrote:
> On 2014-06-01 10:35, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>>          perl -wlpe "s[\w]"
>>
>> Probably it is there from Perl v1 (or v2???).  I have no clue how to
>> fix it (if what I suspect is causing this holds — well, what I suspect
>> does not match how this program BEHAVES).
>
> perl -MO=Deparse -wlpe "s[\w]" shows:
>
> LINE: while (defined($_ = <ARGV>)) {
>      chomp $_;
>      s/\w/}continue{print or die qq(-p destination: $!\n)/;
> }
>
> It's pretty clear what happens and why it behaves as it does:
>
> s[\w] is wrapped in the loop:
>
>      LINE: while (defined($_ = <ARGV>)) { chomp $_; s[\w];}continue{print or die qq(-p destination: $!\n);}
>
> and when that is parsed, the ; after s[\w] is taken as the start of the
> substitution pattern. That ends at the next ; and the final } closes the
> loop. Perfectly valid perl, but not what was intended.
>
> That's the kind of gotchas that happens with pure text substitution. The
> C preprocessor has similar issues.
>
> Theoretically that could be fixed by first compiling the perl fragment
> on the command line and then inserting the finished optree into the
> loop. But I'm not sure if this is possible without unduly restricting
> the semantics.
>
> I'm also not sure whether it is worthwhile fixing. -e should IMHO only be
> used for very simple programs where an error like this is easy to catch

An inner eval{} wrapping the fragment causes an error to reappear. But 
this bit of micro-managing may not make much sense either...

perl -E ' LINE: while (defined($_ = <ARGV>)) { chomp $_; eval{s[\w];1} 
or die $@;}continue{print or die qq(-p destination: $!\n);}'

-- 
Charles DeRykus







------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4232
***************************************


home help back first fref pref prev next nref lref last post