I do not get an error from your code. I have made a few modifications to improve layout and readability which you may find interesting. I have not really changed the functionality other than adding a die on being unable to open FH2 as suggested by mtmcc.
use strict; use warnings; my %users = %{user_paths()}; foreach my $user (keys %users) { if (-e "$users{$user}/MY_FILE") { open (FH2, "<$users{$user}/MY_FILE") or die "could not open $u +sers{$user}/MY_FILE $!"; while (my $line = <FH2>) { if ($line =~ /BASE_PORT=(\d+)/) { print "$user --> $1"; } } } } sub user_paths { my %users; open (FH1, "</etc/passwd") || die "Can't Open : $!"; while (<FH1>) { my @user = split (/:/); if ( $user[2] > 500 ) { $users{$user[0]} = "$user[5]"; } } return \%users; }
In reply to Re: File reading with hashes
by rnewsham
in thread File reading with hashes
by Bindo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |