flipper has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I'm trying to use hash slices, but I get a warning saying Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line 1. - but I don't want a scalar value!
This works OK:
geedorah:/home/wstest# perl -E '$foo{a}=1; $foo{b}=2; say join",", @fo +o{qw#a b#}' 1,2
But with warnings:
geedorah:/home/wstest# perl -wE '$foo{a}=1; $foo{b}=2; say join",", @f +oo{qw#a b#}' Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line +1. 1,2
But if I take perl's advice, it (unsurprisingly) doesn't work:
geedorah:/home/wstest# perl -wE '$foo{a}=1; $foo{b}=2; say join",", $f +oo{qw#a b#}' Use of uninitialized value within %foo in join or string at -e line 1.
Thanks,
Petegeedorah:/home/wstest# cat /etc/debian_version 6.0.1 geedorah:/home/wstest# perl --version This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi (with 51 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. geedorah:/home/wstest#
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Incorrect warning when using hash slices?
by toolic (Bishop) on Apr 26, 2011 at 15:27 UTC | |
by ikegami (Patriarch) on Apr 26, 2011 at 16:03 UTC | |
|
Re: Incorrect warning when using hash slices?
by ikegami (Patriarch) on Apr 26, 2011 at 16:09 UTC | |
by davido (Cardinal) on Apr 26, 2011 at 16:50 UTC | |
by moritz (Cardinal) on Apr 27, 2011 at 08:08 UTC | |
|
Re: Incorrect warning when using hash slices?
by Anonymous Monk on Apr 26, 2011 at 15:14 UTC |