kansas-city-pm-list  

RE: 5.8.0 changes file

Paul Kulchenko
Thu, 10 Oct 2002 15:26:30 -0700

Hi Garrett,

> 1..5 are numeric literals. I would have expected an error like:
> 
> Can't modify constant item in postincrement (++) at ...
>   or
> Modification of a read-only value attempted at ...
no. 1,2,3 are literals, but 1..5 is operator.

[perlop.pod]
Binary ".." is the range operator, which is really two different
operators depending on the context.  In list context, it returns an
array of values counting (up by ones) from the left value to the
right value.

it has the same effect as if you would get using an anonymous array:

$_++ for (@{[1,2,3]})

Comma is different.

[perlop.pod]
In list context, it's just the list argument separator, and inserts
both its arguments into the list.

As you see, comma creates a list (which is not always modifiable)
whereas '..' creates an array, which is modifiable (even if there is
no way to get modified values, because it's anonymous ;)).

lists != arrays. Arrays are assignable by itself. Lists are
assignable only when their values are assignable:

(1,2) = ....
vs.
($a, $b) = ....

Best wishes, Paul.

--- Garrett Goebel <[EMAIL PROTECTED]> wrote:
> From: david nicol [mailto:[EMAIL PROTECTED]]
> > >
> > >    for (1..5) { $_++ }
> > > 
> > > works without complaint.  It shouldn't.
> ...
> > 
> > Who says that modifying $_ here causes a problem? 
> 
> 1..5 are numeric literals. I would have expected an error like:
> 
> Can't modify constant item in postincrement (++) at ...
>   or
> Modification of a read-only value attempted at ...
> 
> as you get with: 
>   print 1++;
>     and
>   sub foo { print $_++ } foo(1);
> 
> 
> I'd be interested to hear the rationalization from perl5-porters as
> to why
> it isn't a bug... if that is what their consensus is.
> 
> --
> Garrett Goebel
> IS Development Specialist
> 
> ScriptPro                   Direct: 913.403.5261
> 5828 Reeds Road               Main: 913.384.1008
> Mission, KS 66202              Fax: 913.384.2180
> www.scriptpro.com          [EMAIL PROTECTED]
> 
>  
> 


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com