Hi everyone, I have 2 open input files F0 and F1 and trying to read the second (F1) which contains IPs only but get the first instead when using print "$_ at line 9 3    PORT    state    protocol I m suppored to get and IP as in 1.0.131.74 what s wrong
here I read a second file F1 (line 9) while within a while loop for the second (line 9) and first file F0 (line 3)
I have read
the open function http://perldoc.perl.org/functions/open.html https://www.perltutorial.org/perl-open-file/ https://perldoc.perl.org/functions/open
the read file https://www.perltutorial.org/perl-read-file/
Open and read https://perlmaven.com/open-and-read-from-files
I have double checked the program command line arguements perl code.pl port.txt IP.txt output.txt here are the
program
open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; /^[0-9]+/; $line=$'; $line_no=$&; while (<F1> && ($line_stop++ < $line_no)) { while (s/^[\ \t]//g) { +}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; print "$_\n";} print F2 $IP, "\t$line\n" if /[0-9]+\//; } close F0; close F1; close F2;
IP file
1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72
port file
3 PORT state protocol 3 80/tcp closed http 3 443/tcp closed https 3 8080/tcp open http-proxy 5 80/tcp open http 5 443/tcp filtered https 5 8080/tcp filtered http-proxy
can someone tell me why I m reading from the wrong filehandle
Thanks for you help

In reply to reading the wrong input file out of 2 opened file by perl_boy

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.