in reply to Erm? Bug or not? Weird behaviour in hash / list conversion
results in the already observed behaviourperl -MData::Dumper -e "for (1 .. 6){print join('.',%h = (1) x $_) . \ +"\n\";print Dumper(\%h)}"
whereas1 $VAR1 = { '1' => undef }; 1.1 $VAR1 = { '1' => 1 }; 1..1 $VAR1 = { '1' => undef }; 1..1.1 $VAR1 = { '1' => 1 }; 1..1..1 $VAR1 = { '1' => undef }; 1.1.1..1.1 $VAR1 = { '1' => 1 };
results inperl -MData::Dumper -e "for (1 .. 6){%h=(1) x $_;print join('.',%h ) . + \"\n\";print Dumper(\%h)}"
which is correct. The question would seem to me to be "why is the 'x' operator propogating to the join?". My guess is that the join is executed for every iteration of the "x", i.e. every time the assignment is triggered %h is updated and the join is executed. (BTW, the undef values are correct and to be expected - see the Dumper results above).1. $VAR1 = { '1' => undef }; 1.1 $VAR1 = { '1' => 1 }; 1. $VAR1 = { '1' => undef }; 1.1 $VAR1 = { '1' => 1 }; 1. $VAR1 = { '1' => undef }; 1.1 $VAR1 = { '1' => 1 }
rdfield
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Erm? Bug or not? Weird behaviour in hash / list conversion
by BrowserUk (Patriarch) on Oct 29, 2003 at 10:31 UTC | |
by sauoq (Abbot) on Oct 29, 2003 at 10:41 UTC | |
by rdfield (Priest) on Oct 29, 2003 at 11:30 UTC |