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

itortuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

clockwatcherCommented:
print $hash{'10152151'};

print $course{"10152151"};

for $key (keys %hash) { print "$key = $hash{$key}\n"; }
itortuAuthor Commented:
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?
Adam314Commented:
#!/usr/bin/perl

use warnings;

# hash       key                   value

%hash =    ('10152150' => 'book 1',
                  '10152151' => 'book 2',
                  '10152155' => 'book 3',
                  '10152156' => 'book 4'
                 );

my $key='10152151';
print "'$key' => '$hash{$key}'\n";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

mjcoyneCommented:
#!/usr/bin/perl -w
use strict;
use warnings;

my %hash = (
    '10152150' => 'book 1',
    '10152151' => 'book 2',
    '10152155' => 'book 3',
    '10152156' => 'book 4'
           );

print "The value associated with key 10152151 is $hash{10152151}\n";
ahoffmannCommented:
print "key:10152151, value:".$hash{'10152151'};
# or in a loop
for my $key (keys %hash) { printf"%s => %s\n",$key,$hash{$key}; }
ozoCommented:
$course{"10152151"}
has nothing to do with
$course

$course{"10152151"} is an element of %course
which is different from %hash
ahoffmannCommented:
> .. has nothing to do with
probably it was meant:
  print join(" ",values %course);
or
  print join(" ",values %hash);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.