print "$user is in the hash. \n"; @user_array = split(/ /, $p2i{$user}); foreach (@user_array) { print "$_\n"; } #### #!/usr/bin/perl use strict; use warnings; my $file = "p2iextact.txt"; my %p2i; my @user_array; my $sp; my $ipr; my $key; my $user; # creates hash of arrays open(FILE, "p2iextact.txt") || die "can't open file"; while() { chomp; ($sp, $ipr) = split; if (exists $p2i{$sp}) { push @{$p2i{sp}}, $ipr; } else { $p2i{$sp}= [$ipr]; } } close FILE; # test to see if hash created correctly foreach $key (sort keys %p2i) { print "$key\t$p2i{$key}\n"; } print "Please enter an ID: "; chomp( $user = ); # try to used uppercaes function to avoid errors $user = uc($user); #see if id is in the hash and print @vals if (exists $p2i{$user}) { print "$user is in the hash. \n";if (exists $p2i{$user}) { print "$user is in the hash. \n"; @user_array = split(/ /, $p2i{$user}); foreach (@user_array) { print "$_\n"; } # print "$user: @{ $p2i{$user} }\n"; # only retieves one value even when more than one #val even if there are multiple } else { print "$user is not in the hash.\n"; } exit;