Bindo has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File reading with hashes
by kcott (Archbishop) on Aug 08, 2013 at 07:26 UTC | |
by Bindo (Acolyte) on Aug 08, 2013 at 08:33 UTC | |
|
Re: File reading with hashes
by mtmcc (Hermit) on Aug 08, 2013 at 07:07 UTC | |
by Bindo (Acolyte) on Aug 08, 2013 at 08:01 UTC | |
|
Re: File reading with hashes
by rnewsham (Curate) on Aug 08, 2013 at 07:17 UTC | |
by Bindo (Acolyte) on Aug 08, 2013 at 08:30 UTC | |
by Random_Walk (Prior) on Aug 08, 2013 at 09:32 UTC | |
by Bindo (Acolyte) on Aug 08, 2013 at 10:01 UTC | |
by rnewsham (Curate) on Aug 09, 2013 at 07:31 UTC | |
by Random_Walk (Prior) on Aug 08, 2013 at 11:22 UTC | |
by Bindo (Acolyte) on Aug 09, 2013 at 12:04 UTC | |
by poj (Abbot) on Aug 09, 2013 at 13:21 UTC |