Gentlemen I have a file called "MY_FILE" with a certain string(BASEPORT=1000) along with other information, placed on all system user's home directory. I want to have the name of the system user and the value that is mentioned under BASEPORT parameter to be printed on to the screen in following manner
User1 --> 1000
User2 --> 5000
I get the following error with what I have attempted so far
readline() on closed filehandle FH2 at ./base_ports.pl line 12, <FH2> line 3103
Following is the script
my %ARR1 = uid(); foreach my $TAB (keys %ARR1) { if (-e "$ARR1{$TAB}/MY_FILE") { open (FH2, "<$ARR1{$TAB}/MY_FILE"); while (my $STRING = <FH2>) { if ($STRING =~ /BASE_PORT=(\d+)/) { my $STRING = $1; print "$TAB --> $STRING"; } } } } 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]'); $UID_PATH{$USER} = "$UID[5]"; } } return %UID_PATH; }
Please could you help. Please feel free to modify the code. Many thanks in advance
./Bindo
In reply to File reading with hashes by Bindo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |