Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: can't read the 2nd input file

by tybalt89 (Monsignor)
on May 07, 2022 at 21:12 UTC ( [id://11143654]=note: print w/replies, xml ) Need Help??


in reply to can't read the 2nd input file

NOTE: requires portfile to be in sorted order

NOTE: The IPfile read should be in the body of the "while", not in the condition.

NOTE: "goto" not required.

NOTE: Does not even have to read all the way through the IPfile if no IPs that are near the end are referenced.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129698 use warnings; @ARGV = qw( port.file ip.file out.file); # FIXME only for testing @ARGV == 3 or die "wrong number of arguments"; open $_, '<', shift or die for my( $F0, $F1); open $_, '>', shift or die for my $F2; my ($no, $IP) = 0; while( <$F0> ) # NOTE assumes port file is in sorted order { my ($stop, $port) = /^(\d+)\s+(.*\n)/; $no += ($IP = <$F1> // die) =~ /^(?:\d+\.){3}\d+\s+\z/ while $no < $ +stop; print $F2 $IP =~ s/\s+\z//r, "\t$port"; } close $F2; system 'cat out.file'; # FIXME only for testing

Outputs (for your larger example with blank lines in the IP file):

1.0.0.29 80/tcp closed http 1.0.0.29 443/tcp closed https 1.0.0.29 8080/tcp open http-proxy 1.0.0.49 80/tcp open http 1.0.0.49 443/tcp filtered https 1.0.0.49 8080/tcp filtered http-proxy 1.0.0.69 80/tcp open http 1.0.0.69 443/tcp filtered https 1.0.0.69 8080/tcp filtered http-proxy

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11143654]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found