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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.