I really don't want to be a layout enforcer. Since no one has brought it up, please Clean your room before posting.

You can use whitespace and indenting to convey helpful information. We want to help - make it easy on us.

#!/usr/bin/perl use strict; use warnings; my $input = ''; my %nme = (); my $fn = ''; my $ln = ''; while() { print "enter the name\n"; chomp($input=<STDIN>); if($input ne '') { ($fn, $ln) = split('',$input); print "$fn, $ln\n"; $nme{$ln} = $fn; } else { last; } foreach my $lastname(sort keys %nme) { print "$lastname, $nme{$lastname}\n"; }
This is much easier to read and, we see right there you're missing a final curly. I'm sure that's a copy-n-paste error, but wouldn't it be nice if you showed syntactically correct code to people who are helping you (at the very least it keeps us away from a red herring).

Always use strict; and use warnings;. Even if it would not have helped you here, you need to get into the habit. You took the time to preset your vars, there is no reason not to have strict and warnings on.

UPDATE: fixed link - Thanks Albannach and added strict and warnings for demonstration - Thanks Grandfather

grep
XP matters not. Look at me. Judge me by my XP, do you?


In reply to Re: Problem in printing lastname and firstname by grep
in thread Problem in printing lastname and firstname by Anonymous Monk

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.