[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Fun with ++



On Thu, Aug 19, 1999 at 11:03:58AM -0700, Peter Scott wrote:
> Having some fun in 5.004_04.  Do you know without trying it what this does:
> 
> use strict;
> use Data::Dumper;
> my %h;
> @h{qw/1 2 3/}++;
> print Dumper (\%h), "\n";
> 
> Now if you understand the answer, what should the result of this be:
> 
> use strict;
> use Data::Dumper;
> my @a;
> @a[qw/1 2 3/]++;
> print Dumper(\@a), "\n";
> 
> Hint: there's a bit more output.  Why?

*** SPOILER ****




























It's trying to free the zero'th element of the array.
You get the same result if you say this:

  @a[qw/1 2 3/] = ();

but you don't if you say this:

  @a[qw/0 1 2 3/] = ();

-- 
John Porter


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe