in reply to calling a hash

Hai,In the "%random_name" hash, $bob is treated as a string if its not declare.>

Try this,

use strict; my $bob="hai"; my @array=('hai'); my %random_name = ( $bob => "something"); foreach (@array) { my $value = $random_name{$_}; print "value: $value\n"; };

Regards,
Velusamy R.

Replies are listed 'Best First'.
Re^2: calling a hash
by blazar (Canon) on Oct 04, 2005 at 11:28 UTC
    Hai, In the "%random_name" hash, $bob is treated as a string if its not declare.
    really?
    $ perl -MO=Deparse -e '%a=($bob => "foo")' (%a) = ($bob, 'foo'); -e syntax OK
    or
    $ perl -MData::Dumper -e '%a=($bob => "foo"); print Dumper \%a' $VAR1 = { '' => 'foo' };