in reply to Re^4: Adding Unique Elements to Array
in thread Adding Unique Elements to Array
The fact is that your x= tricks works as just as much as the undef() because of undocumented behaviour. This is shown by
or using simpler means:my $foo; sub context :lvalue { $foo = wantarray ? 'list' : 'scalar' } context() x= 1; print $foo; __END__ scalar
A trick that does work though is the reference trick. All these other solutions work because of autovivification. So let's use \ whose behaviour explicitly is documented.use Data::Dumper; my %foo = qw/ a 1 b 2 /; @foo{qw/ a b /} x= 0; print Dumper \%foo; __END__ $VAR1 = { 'a' => '1', 'b' => '' };
\@foo{@list};
ihb
See perltoc if you don't know which perldoc to read!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Adding Unique Elements to Array
by Roy Johnson (Monsignor) on Mar 01, 2005 at 03:43 UTC | |
by ihb (Deacon) on Mar 01, 2005 at 21:19 UTC | |
by Roy Johnson (Monsignor) on Mar 01, 2005 at 21:32 UTC |