On Thu, Nov 15, 2012 at 10:06 PM, Chris Charley <char...@pulsenet.com>wrote:

>
>
> "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: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
> Thanks Chris, I have tested your code, it works, Appreciate it.
i did'nt  use use Inline::Files; i saw a security warning for this module (
It is possible that this module may overwrite the source code in files that
use it. To protect yourself against this possibility, you are
*strongly*advised to use the
-backup option described i )  not sure its something to be concerned about !

Cheers
Sj

Reply via email to