You can use whitespace and indenting to convey helpful information. We want to help - make it easy on us.
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).#!/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"; }
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
| 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |