Welcome to the Monastery | |
PerlMonks |
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 (Novice) |
on Apr 04, 2022 at 16:32 UTC ( [id://11142674]=note: print w/replies, xml ) | Need Help?? |
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
11 versions/programs work from memory
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
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 Section
Seekers of Perl Wisdom
|
|