Ryan Dillinger wrote: > Hello again, I assume that you are replying to my post but it is hard to tell because you have started a new thread with a new Subject line.
> I have rewrote this script I hoped the way you told me. I assume that "you" is me. The comments I made were (mostly) supposed to *replace* the code it followed. > And now I have just one error that states: Use of uninitialized value in > hash element at > names.pl line 24, <> line 1. > Forgive me, but I'm not sure what's going on here. > > > > #!/usr/bin/perl > > use warnings; > use strict; my %names; > while (<>) { > @raw = split; > $names{ $raw[ -1 ] } = "@raw[ 0 .. $raw -1 ]"; > } > > while () { > print "\n1. Sort names by last name\n"; > print "2. Sort names by first name\n"; > print "3. Search for a name\n"; > print "4. Quit\n\n"; > print "Choose a number: "; chomp( my $in = <STDIN> ); > if ($in eq '1') { foreach my $name ( sort $keys %names ) { > print "$name, $names{$name}\n"; > } > } elsif ($in eq '2') { my @keys = sort { $names{$a} cmp $names{$b} } keys %names; foreach my $name ( @keys ) { > print "$names{name} $name\n"; > } > } elsif ($in eq '3') { > print "Search for what? "; chomp( my $search = <STDIN> ); my @keys; while ( my @n = each %names ) { > if (grep /$search/, @n) { > push @keys, $n[ 0 ]; > } > } > if (@keys) { > print "Names matched: \n"; foreach my $name ( sort @keys ) { > print " $names{$name} $name\n"; > } > } else { > print "None found.\n"; > } > } elsif ($in eq '4') { > last; > } else { > print "Not a good answer. 1 to 4 please.\n"; > } > } > > Sorry I just can;t figure it out. Thank You Try it like that. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>