Should the following two lines of code do the same thing?
$hash{$_} ||= 1 + keys %hash for @list; $hash{$_} = $hash{$_} || 1 + keys %hash for @list;
IMO the second one should be well defined. tye and diotalevi think that both are undefined, I could be conviced about the first, but I need more convincing on the second.
This came up because I was being cheeky in Re^3: Perl one-liner to remove duplicate entries from PATH and wound up scratching my head.
use Data::Dump::Streamer; my (%hash,%mash); @list=('A'..'C'); $hash{$_} ||= 1 + keys %hash for @list; $mash{$_} = $mash{$_} || 1 + keys %mash for @list; Dump(\%hash,\%mash)->Names('*hash','*mash')->Out(); __END__ %hash = ( A => 2, B => 3, C => 4 ); %mash = ( A => 1, B => 2, C => 3 );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Are "$hash{$_} ||= 1 + keys %hash" and variants well defined or not?
by bart (Canon) on Jan 12, 2006 at 21:44 UTC | |
Re: Are "$hash{$_} ||= 1 + keys %hash" and variants well defined or not?
by xdg (Monsignor) on Jan 12, 2006 at 22:11 UTC | |
Re: Are "$hash{$_} ||= 1 + keys %hash" and variants well defined or not?
by whio (Beadle) on Jan 13, 2006 at 11:18 UTC | |
Re: Are "$hash{$_} ||= 1 + keys %hash" and variants well defined or not?
by zshzn (Hermit) on Jan 12, 2006 at 21:08 UTC | |
by demerphq (Chancellor) on Jan 12, 2006 at 21:14 UTC |