I made the following -ARGV-line-IP-start to take an extra command line arguement  <LINE_IP_LINE>  $ARGV[3] as a start line number of the IP file  INPUT_FILE_IP, that add that number when reading it. use this AFTER using split. Just man split for details
Everything works find with the same test files
added -ARGV-line-IP-start to the following memory programs filenames
port-state-service+IP-mem-list-direct.pl port-state-service+IP-mem-hash-direct.pl port-state-service+IP-mem-array.pl port-state-service+IP-mem-array-delete.pl port-state-service+IP-mem-array-delete-xtra.pl port-state-service+IP-mem-hash-direct-delete.pl port-state-service+IP-mem-hash-direct-delete-xtra.pl port-state-service+IP-mem-hash-indirect.pl port-state-service+IP-mem-list-indirect.pl port-state-service+IP-mem-list-splice.pl port-state-service+IP-mem-list-splice-xtra.pl

to make
port-state-service+IP-mem-array-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line-IP-start.p +l

added die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3]<=" if $ARGV[3] =~ /[^0-9]/; to check that the third command line arguement is indeed a JUST number and changed
line 1
die "perl port-state-service+IP-mem-array.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2;

to
die "perl port-state-service+IP-mem-array.pl <INPUT_FILE_ports> <INPUT +_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $#ARGV < 3;

line 4 in
port-state-service+IP-mem-array-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line-IP-start.p +l

line 8 in
port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.pl

$line_no=0;
to $line_no=$ARGV[3];

here is the program code


port-state-service+IP-mem-array-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-array-ARGV-line-IP-start.pl <INPUT +_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $#ARGV +< 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP[$line_no++] = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; print F2 $IP[$line_no - 1], "\t$line\n" if /[0-9]+\//; } close F0; close F2;

port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl + <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if +$#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP[$line_no++] = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; if (/[0-9]+\//) { $temp = $IP[$line_no - 1] if $IP[$line_no - 1] ne "";$IP[$line +_no - 1] = ""; print F2 $temp, "\t$line\n";$IP[$line_no - 1] = ""; } } close F0; close F2;

port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-sta +rt.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE> +" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP[$line_no++] = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n";$x = $y = 0; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; if ($y > $x) { for ($z = $x;$z < $y;$z++) { delete $IP[$z]; } } if (/[0-9]+\//) { $temp = $IP[$line_no - 1] if $IP[$line_no - 1] ne "";$IP[$line +_no - 1] = ""; print F2 $temp, "\t$line\n";$IP[$line_no - 1] = ""; } $x = $y; } close F0; close F2;

port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP{$line_no++} = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; print F2 $IP{$line_no - 1}, "\t$line\n" if /[0-9]+\//; } close F0; close F2;

port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-st +art.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE +>" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP{$line_no++} = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; $temp = delete $IP{$line_no - 1} if $IP{$line_no - 1}; print F2 $temp, "\t$line\n" if /[0-9]+\//; } close F0; close F2;

port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line- +IP-start.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP +_LINE>" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP{$line_no++} = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n";$x = $y = 0; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; $temp = delete $IP{$line_no - 1} if $IP{$line_no - 1}; $y = $line_no - 1; if ($y > $x) { for ($z = $x;$z < $y;$z++) { delete $IP{$z}; } } print F2 $temp, "\t$line\n" if /[0-9]+\//; $x = $y; } close F0; close F2;

port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.p +l <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if + $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; sub idx { print F2 $IP{$line_no - 1}, "\t$line\n" if /[0-9]+\//; } open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP{$line_no++} = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\ +.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; &idx; } close F0; close F2;

port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; push @IP,$& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]? +[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; print F2 $IP[$line_no - 1], "\t$line\n" if /[0-9]+\//; } close F0; close F2;

port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.p +l <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if + $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; sub idx { print F2 $IP[$line_no - 1], "\t$line\n" } open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; push @IP,$& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]? +[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; 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;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; &idx; } close F0; close F2;

port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; push @IP,$& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]? +[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n";$temp_IP = "";$y = $z = 0; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; if (/[0-9]+\//) { if ($y != ($line_no - 1)) { $temp_IP = splice(@IP, $line_no - 1 - $z++, 1);$y = $line_ +no - 1; } print F2 $temp_IP, "\t$line\n"; } } close F0; close F2;

port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-start.pl
die "perl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-star +t.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" + if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; push @IP,$& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]? +[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n";$temp_IP = "";$w = $x = $y += $z = 0; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; if (/[0-9]+\//) { if ($y != ($line_no - 1)) { $temp_IP = splice(@IP, $line_no - 1 - $z++, 1);$y = $line_ +no - 1; splice(@IP, $x - $w, $w = abs($y - $x - $w - 1)); $z += ($y - $x - 1);$x = $y; } print F2 $temp_IP, "\t$line\n"; } } close F0; close F2;


In reply to Re: can't read the 2nd input file;partial memory via IP start (ARGV 3) using split 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.