I have made 12 new versions/programs from port-state-service+IP-mem.pl (now renamed port-state-service+IP-mem-array.pl) and port-state-service+IP-disk.pl now renamed port-state-service+IP-disk-sub.pl
3 versions/programs work from disk
port-state-service+IP-disk-goto.pl port-state-service+IP-disk-sub.pl port-state-service+IP-disk-while.pl

11 versions/programs work from memory
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

The ones operating from disk is in the case where the list is IPs taken from IP.txt file, which may be very big will not fit in a computers memory (some legacy computers from the 70/80 have only 64K!) in which case will work much slower due to frequent disk access
Those are goto, sub and while.
The goto version is a bit contreversial and the black sheep since it uses a goto to jump in goto get_IP (line 13) and out goto CONT (line 20) of the outter while (line 7) loop and I was a bit hesitant of including it here,but I did EVERYTHING I could, but could not find any instruction/statement/command to return from a goto (see below) and decided to post it anyway for completeness
The sub version uses a subroutine calling &get_IP (line 13) defined below (lines 18 .. 28)
The while version uses an inner while loop (lines 13 .. 15)
I did the port-state-service+IP-disk-while.pl from port-state-service+IP-disk-goto.pl replacing goto get_IP with the code of that label , indented and deleted the labals get_IP CONT END
All 3 versions (subroutine calling &get_IP, while loop, goto get_IP label) read the IP.txt file upto the line number 1st column ($1 as in awk) of port.txt file and prints the IP associated with the nth,that is, that number
The ones operating from memory are much faster since IPs are fetched directly from memory. They use 3 different data structures (array, list, hash) from perl to store IPs read from IP.txt
list and hash both have a direct and indirect version. The direct version port-state-service+IP-mem-list-direct.pl and port-state-service+IP-mem-hash-direct.pl read from the data structure (list, hash) itself without passing by a subroutine, while the indirect version port-state-service+IP-mem-hash-indirect.pl and port-state-service+IP-mem-list-indirect.pl uses the idx subroutine
The array and hash both have 2 delete versions
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

the delete ONLY versions port-state-service+IP-mem-array-delete.pl and port-state-service+IP-mem-hash-direct-delete.pl delete ONLY the index item while port-state-service+IP-mem-array-delete-xtra.pl and port-state-service+IP-mem-hash-direct-delete-xtra.pl delete items between interveining line numbers from the port.txt file

In reply to Re: can't read the 2nd input file;12 new versions of PORT-STATE-SERVICE+IP;14 in all;3 disk,11 memory (part 1) 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.