here are 4 new versions of the already posted (up on this page) goto version. 2 of them port-state-service+IP-disk-goto-if.pl and port-state-service+IP-disk-goto-if-2.pl work without warning and them 2 last port-state-service+IP-disk-goto-2.pl and port-state-service+IP-disk-goto-3.pl print Use of "goto" to jump into a construct is deprecated at temp-1.pl line 29, <F1> line because goto is used from outside,that is, from inside get_IP contrarely to the 2 first who use goto from the inside if/while,this is because perl have to statement/command to return from where it left (ex: a return inside a sub) so I still decided to post/upload them anyway for completeness
port-state-service+IP-disk-goto-if.pl copied from port-state-service+IP-disk-while.pl and tested using the same files output the same results (using diff (empty))
changed while for if and inserted/prepended label at line 12 and added goto label at end of line 13 tested with both IP files each containing 10 and 100 IPs using input files containing {3 5 7} and {30 50 70} line numbers;both OK
port-state-service+IP-disk-goto-if-2.pl copied from port-state-service+IP-disk-goto-if.pl and tested using the same files output the same results (using diff (empty))
changed while for if and inserted $_ = inside if at line 7 and inserted label0 at line 6 and added goto label0 at line 22 Also changed label to label1 at lines 13 and 14
port-state-service+IP-disk-goto-2.pl copied from port-state-service+IP-disk-goto.pl and tested using the same files output the same results (using diff (empty))
changed while for if and inserted $_ = inside if at line 7 and inserted label at line 6 and added goto label at line 16
port-state-service+IP-disk-goto-3.pl copied from port-state-service+IP-disk-goto-2.pl and tested using the same files output the same results (using diff (empty))
changed while for if and inserted $_ = inside if at line 22 added goto get_IP at line 23

port-state-service+IP-disk-goto-if.pl
die "perl port-state-service+IP-disk-goto-if.pl <INPUT_FILE_ports> <IN +PUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; label: if (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9 +]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; goto label; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line +_IP =~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; } } } close F0; close F1; close F2;

port-state-service+IP-disk-goto-if-2.pl
die "perl port-state-service+IP-disk-goto-if-2.pl <INPUT_FILE_ports> < +INPUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; label0: if ($_ = <F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; label1: if (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9 +]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; goto label1; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line +_IP =~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; } } goto label0; } close F0; close F1; close F2;

port-state-service+IP-disk-goto-2.pl
die "perl port-state-service+IP-disk-goto-2.pl <INPUT_FILE_ports> <INP +UT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; label: if ($_ = <F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; goto get_IP; CONT: } goto label; } close F0; close F1; close F2; goto END; get_IP: while (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0 +-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line_IP +=~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; goto CONT; } goto CONT; END:

port-state-service+IP-disk-goto-3.pl
die "perl port-state-service+IP-disk-goto-3.pl <INPUT_FILE_ports> <INP +UT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; label: if ($_ = <F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; goto get_IP; CONT: } goto label; } close F0; close F1; close F2; goto END; get_IP: if (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0 +-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/;goto get_IP; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line_IP +=~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; goto CONT; } goto CONT; END:


In reply to Re: can't read the 2nd input file;4 new versions of goto by perl_boy
in thread can't read the 2nd input 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.