Your code executes just fine for me; specifically I get:

user@localhost:~/sandbox$ perl script.pl Enter a name to print it's family name : Alis Alis is already there, and its family name is Williams user@localhost: +~/sandbox$

How are you attempting to interact with it?

On a side note, hashes are wonderful tools, but you are not using them to their greatest advantage. To quote a great man:

Doing linear scans over an associative array is like trying to club someone to death with a loaded Uzi. -- TimToady

Rather than what you've written, I would use code more like:

#!/usr/bin/perl -w use strict; my %family_name = ( "Alis" => "Williams", "Sara" => "McAwesome", "Serena" => "Anderson", ); print "Enter a name to print it's family name : \n"; chomp(my $name= <STDIN>); if (exists $family_name{$name}) { print "$name is already there, and its family name is $family_name +{$name} "; } else { print "I don't know anyone by the name $name\n"; }

See exists for info on the exists function and perldata for info on what data types (including hashes) Perl has to offer.


In reply to Re: Comparing Hash's key to an <STDIN> and print it's corresponding value by kennethk
in thread Comparing Hash's key to an <STDIN> and print it's corresponding value by xxArwaxx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.