itortu
asked on
hash element interpolation
I am trying to print out the key and a value of 10152150, but i keep getting errors about an uninitialized value in the print line
and another Name "main::hash" used only once. Can someone show me how can I correct this? Thank you.
#!/usr/bin/perl
use warnings;
# hash key value
%hash = ('10152150' => 'book 1',
'10152151' => 'book 2',
'10152155' => 'book 3',
'10152156' => 'book 4'
);
$course{"10152151"} = 'book 2';
print "$course";
and another Name "main::hash" used only once. Can someone show me how can I correct this? Thank you.
#!/usr/bin/perl
use warnings;
# hash key value
%hash = ('10152150' => 'book 1',
'10152151' => 'book 2',
'10152155' => 'book 3',
'10152156' => 'book 4'
);
$course{"10152151"} = 'book 2';
print "$course";
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> .. has nothing to do with
probably it was meant:
print join(" ",values %course);
or
print join(" ",values %hash);
probably it was meant:
print join(" ",values %course);
or
print join(" ",values %hash);
ASKER
#!/usr/bin/perl
use warnings;
# hash key value
%hash = ('10152150' => 'book 1',
'10152151' => 'book 2',
'10152155' => 'book 3',
'10152156' => 'book 4'
);
for $key (keys %hash) {
print "$key = $hash{$key}\n";
}
how can i print out the key and the value '10152151' => 'book 2',
without printing all the others?