in reply to IP Address consolidation
If you have overlapping entries in the different files, then you will have to check on insert. This could be done with a Hash of Hashes (HoH):my %data; foreach my $file (@file_list) { open (INPUT, $file) || warn "Could not read $file\n"; while (<INPUT>) { chomp; my ($start,$end,$name) = split (/,/); push (@{$data{$name}}, "$start,$end"); } close (INPUT); } foreach (sort keys %data) { print "@{$data{$_}},$_\n"; }
The reason for using inet_aton (ASCII to Number) from the Socket module is to simplify comparisons. "202.1.2.0" and "202.01.002.0" are equivalent, and removing redundant zeros is a lot more complicated than just "packing" them into their native format (4 bytes). They are easily unpacked with the complementary inet_ntoa (Number to ASCII), and should always come out clean with no extraneous zeros.use Socket; my %data; foreach my $file (@file_list) { open (INPUT, $file) || warn "Could not read $file\n"; while (<INPUT>) { chomp; my ($start,$end,$name) = split (/,/); $start = inet_aton($start); $end = inet_aton($end); if (defined $data{$name}{$start}) { # Resolve conflict? } else { $data{$name}{$start} = $end; } } close (INPUT); } foreach my $name (sort keys %data) { foreach my $start (sort keys %{$data{$name}}) { print join (',', inet_ntoa($start), inet_ntoa($end), $name), "\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: IP Address consolidation
by yasysad (Novice) on Aug 20, 2001 at 16:58 UTC | |
|
Re: Re: IP Address consolidation
by yasysad (Novice) on Aug 20, 2001 at 15:03 UTC |