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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Retunining hash values from subroutines
by Bindo (Acolyte) on Jun 20, 2013 at 12:16 UTC | |
by packetstormer (Monk) on Jun 20, 2013 at 12:59 UTC | |
by Laurent_R (Canon) on Jun 20, 2013 at 21:24 UTC |