"jet speed" wrote in message news:CAG1VzcezebNiFar3YKep-
What i am trying to do ?
I want to match the entries from file1.txt with file.txt, if matches then
print the key and value. some will have multiple entries as in the output.
required output
10.00.00.00.aa.56.9b.7a 22:5a
10.00.00.00.aa.57.99.8a 22:5a
10.00.00.00.aa.46.9b.33 32:9c
10.00.00.00.aa.5a.9b.63 a2:cc
10.00.00.00.aa.5a.9b.63 a5:cc
10.00.00.00.aa.5a.9b.63 b2:cc
file1.txt
10.00.00.00.aa.56.9b.7a
10.00.00.00.aa.57.99.8a
10.00.00.00.aa.46.9b.33
10.00.00.00.aa.5a.9b.63
file.txt
22:5a => 10.00.00.00.aa.56.9b.7a
22:5a => 10.00.00.00.aa.57.99.8a
32:9c => 10.00.00.00.aa.46.9b.33
a2:cc => 10.00.00.00.aa.5a.9b.63
a5:cc => 10.00.00.00.aa.5a.9b.63
b2:cc => 10.00.00.00.aa.5a.9b.63
b2:55 => 10.00.00.00.aa.5a.9b.d8
Here is a solution according to the specs (above).
#!/usr/bin/perl
use strict;
use warnings;
use Inline::Files;
my %data;
while (<FILEB>) {
my ($val, $key) = /^(\S+) => (.+)$/;
push @{ $data{$key} }, $val;
}
while (my $key = <FILEA>) {
chomp $key;
for my $val (@{ $data{$key} }) {
print "$key $val\n";
}
}
__FILEA__
10.00.00.00.aa.56.9b.7a
10.00.00.00.aa.57.99.8a
10.00.00.00.aa.46.9b.33
10.00.00.00.aa.5a.9b.63
__FILEB__
22:5a => 10.00.00.00.aa.56.9b.7a
22:5a => 10.00.00.00.aa.57.99.8a
32:9c => 10.00.00.00.aa.46.9b.33
a2:cc => 10.00.00.00.aa.5a.9b.63
a5:cc => 10.00.00.00.aa.5a.9b.63
b2:cc => 10.00.00.00.aa.5a.9b.63
b2:55 => 10.00.00.00.aa.5a.9b.d8
__END__
*** ouput run
C:\Old_Data\perlp>perl t33.pl
10.00.00.00.aa.56.9b.7a 22:5a
10.00.00.00.aa.57.99.8a 22:5a
10.00.00.00.aa.46.9b.33 32:9c
10.00.00.00.aa.5a.9b.63 a2:cc
10.00.00.00.aa.5a.9b.63 a5:cc
10.00.00.00.aa.5a.9b.63 b2:cc
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/