develooper Front page | perl.perl5.porters | Postings from March 2001

Re: unexpected result of stringification.

Thread Previous | Thread Next
From:
nick
Date:
March 19, 2001 13:34
Subject:
Re: unexpected result of stringification.
Message ID:
E14f7E6-0000E7-00@roam1
Chris Stith <mischief@velma.motion.net> writes:
>That is so if the examples are taken exactly as is. It is not so if
>the example is put in the context of code following it. From which
>match operator would the next line pull `$1'?
>
>Nick is talking about a body of code expecting something to be a
>certain way when the code example above is executed. 

No I am not. (The example code is not mine and not a good example.
It has && in it, is calling a builtin as a pseudo-sub and ...)

I am talking about code that uses $1 in general, and with at least 
a basic grasp of how the op tree is built. And with a background
in devious "lexing" schemes. 

Without a lot of flow analysis (that perl does not do) perl cannot tell 
that a particular use of $1 is (always) used in a way that means it should
take a copy, or a way which means it should leave it "lazy".

So my stance is that $1 is lazy, if you want/need a copy then write "$1".

>A line of
>code following the above example shouldn't expect one or the other
>expression to be either `first' or `last', let alone expect which one
>will be the value of `$1'.

Things get less clear when you have something like:

  some_sub( (s/(0x([a-f0-9]+))/another_sub($1)/ie || s/(\d+)/third($1)/e) ?  $1 : ... );

In such cases "lazy" is what _I_ want for that last one at least and only 
by a lot of looking do you know which that is.


>
>Chris Stith
-- 
Nick Ing-Simmons


Thread Previous | Thread Next


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