[32952] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4228 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 1 09:09:15 2014

Date: Sun, 1 Jun 2014 06:09:03 -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           Sun, 1 Jun 2014     Volume: 11 Number: 4228

Today's topics:
        Delicious Perl bug <nospam-abuse@ilyaz.org>
    Re: Delicious Perl bug <hjp-usenet3@hjp.at>
    Re: Issue: unexpected value in $2 (Perl 5.10.1) <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 1 Jun 2014 10:35:08 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Delicious Perl bug
Message-Id: <lmevks$aa2$1@dont-email.me>

        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).

Enjoy,
Ilya

P.S.  BTW, I cannot get -d go past line 1 (even with v).  Why?


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

Date: Sun, 1 Jun 2014 14:42:53 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: Delicious Perl bug
Message-Id: <slrnlom7uj.o4f.hjp-usenet3@hrunkner.hjp.at>

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.

> P.S.  BTW, I cannot get -d go past line 1 (even with v).  Why?

Because there is only one line?

        hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sun, 1 Jun 2014 11:34:59 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Issue: unexpected value in $2 (Perl 5.10.1)
Message-Id: <lmf353$qoh$1@dont-email.me>

On 2013-03-23, John Bokma <john@castleamber.com> wrote:
> Klaus <klaus03@gmail.com> writes:
>
>> However, the following line is not safe:
>>
>>> > $seconds_since_epoch = timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 );
>
> Can you give me an example of calling a sub that shows this unsafe
> behavior? And/or the scoping issues you mention?
>
> I've always considered it perfectly safe to do something like:
>
> $foo =~ /(.)/;
> bar( $1 );
>
> if not, I like to know cases this can go wrong. Thanks.

While the answer to your question was already demonstrated in this
thread (a year ago!), I still want to add my 2¢: I ***always*** write
such calls as
  bar "$1";

I think that the slowdown is negligible, while the benefits are
enormous (you may guess that I spent many hours tracing this kind of bugs).

Yours,
Ilya


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

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 4228
***************************************


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