List Info

Thread: Re: Odd hash behavior...




Re: Odd hash behavior...
country flaguser name
United States
2007-09-07 06:49:37

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, Ryan J Nauman <RJNauman...> wrote:
&gt;
> I have the following code for pushing a new value onto my hash:
&gt;
> my %buckets;
> push({ $buckets{&quot;KEYNAME"} }, "new value";);
> my keys = keys %buckets;
> my values = values %buckets;
> print %buckets;
> print "nkeys[0] => values[0]&quot;;
&gt;
> This code yields the following output...
>
> KEYNAMEARRAY(0x15d702c)
> KEYNAME => ARRAY(0x15d702c)
&gt;
> Why won't it print "new value"; ???
>
> I'm running perl, v5.8.8 build 822 from ActiveState.
>
> [Non-text portions of this message have been removed]
>

With

use strict;
use warnings;

you get the hint that you are not using Perl properly.

Scalar value keys[0] better written as $keys[0] at t.pl line 10.
Scalar value values[0] better written as $values[0] at t.pl line 10.

my %bucket = (
KEYNAME => 'new value',
ANOTHER => 'another value',
);

foreach my $key (keys %bucket) {
print "key = $key, value = $bucket{$key}n";
}

for more information -> web search "perl hash howto";

gl

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )