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

Since you provided your code and sample input and output data, I'll give you some code to get you started:

#!/usr/bin/env perl use warnings; use strict; use Data::Dumper; # for debugging $Data::Dumper::Useqq=1; my $DEBUG = 1; die "Usage: $0 <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE>" if @ARGV!=3; my ($PORTS_FILE, $IPS_FILE, $OUT_FILE) = @ARGV; open my $ip_fh, '<:crlf', $IPS_FILE or die "$IPS_FILE: $!"; chomp( my @ips = <$ip_fh> ); close $ip_fh; print Data::Dumper->Dump([\@ips], ['*ips']) if $DEBUG; open my $out_fh, '>', $OUT_FILE or die "$OUT_FILE: $!"; open my $port_fh, '<:crlf', $PORTS_FILE or die "$PORTS_FILE: $!"; my $header = <$port_fh>; while ( my $line = <$port_fh> ) { chomp($line); my ($line_nr,$rest) = $line =~ /^(\d+)(\s+.+)$/ or die "Failed to parse line: $_"; print Data::Dumper->Dump([$line_nr,$rest], [qw/line_nr rest/]) if $DEBUG; die "Invalid line number: $line_nr" if $line_nr < 1 || $line_nr > @ips; my $ip = $ips[ $line_nr - 1 ]; print Data::Dumper->Dump([$ip], ['ip']) if $DEBUG; print {$out_fh} $ip, $rest, "\n"; } close $port_fh; close $out_fh;

Note that this makes a few small assumptions:

Replies are listed 'Best First'.
Re^2: can't read the 2nd input file
by perl_boy (Novice) on Feb 03, 2022 at 16:20 UTC
    Sorry for the detail. I'v complete forgotten this program as another guy on the job found a similar program. I stumble on this forgotten program as I was sorting out files.
    the memory version reads the IP file and into memory and prints the IP from the array to the output file
    the disk version reads a files at once, altering from one file to the other until it find the numbered IP then write the IP and associated ports to the output file.
    the memory version is much faster and thus much easier to write but may not work on computers with less memory. the disk version is much slower due to frequent disk access.
    port-state-service+IP-mem.pl and port-state-service+IP-disk.pl https://www.perlmonks.com/?node_id=11129698
    thank you for your help.