http://qs1969.pair.com?node_id=1039956


in reply to Retunining hash values from subroutines

You could be a bit cleaner still and not declare the %UID_PATH hash as many times. Also, as stated above, the reason you were getting one line is that your return value was within the while loop, meaning the only the last value would be returned. Moving it outside and cleaning up a little as below:

#!/usr/bin/perl use strict; my %ARR1 = uid(); foreach my $TAB (keys %ARR1) { print "User --> $TAB, Value --> $ARR1{$TAB}\n"; } sub uid { my %UID_PATH; open (FH1, "</etc/passwd") || die "Can't Open : $!"; while (<FH1>) { my @UID = split (/:/, $_); if ($UID[2] > 500) { my $USER = "$UID[0]"; $UID_PATH{$USER} = "$UID[5]"; } } return %UID_PATH; }