Link to home
Start Free TrialLog in
Avatar of itortu
itortuFlag for United States of America

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";

SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itortu

ASKER

i put it together like this:

#!/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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> .. has nothing to do with
probably it was meant:
  print join(" ",values %course);
or
  print join(" ",values %hash);