in reply to Keys/Values being lost with this code--any help?

Did you mean this?
my %hash_list = map { split ' ' } split(/,/, $names);
This would creat a hash of the form:
%hash_list = ( John => 20, Bill => 34, Jane => 28, Wall => 18, Tom => 19 );

Replies are listed 'Best First'.
Re: Re: Keys/Values being lost with this code--any help?
by ByteOrNybble (Novice) on Sep 24, 2002 at 15:28 UTC
    Thanks to all for your replies! This is what I was looking for. I must apologize for not being able to state what I needed in an understandable fashion. Please excuse me as I am still new to Perl and am just getting comfortable with the language! Thanks! PS: What would you use to sort this? Either by the key or by the value--which subroutines can be used? Thanks again.
      ## assuming my %hash = ( John => 20, Bill => 34, # etc... ); ## sort by name(key): foreach my $name ( sort keys %hash ) { print "$name: $hash{$name}\n"; } ## sort by number(value): foreach my $name ( sort { $hash{$a} <=> $hash{$b} } keys %hash ) { print "$name: $hash{$name}\n"; }