Hi KKK, to celebrate your achievement in reaching -100 XP, here's my code...
use strict;
# set up @f1 and @f2 to mimic the two files
my $f1 = 1;
my (@f1, @f2);
while(<DATA>){
next unless /\S/;
chomp;
$f1 = 0 if /^f2$/;
push @f1, $_ if $f1;
push @f2, $_ unless $f1;
}
shift @f1; shift @f2; # remove 'f1' and 'f2'
# process file1 - basically use headers as hash keys, then fields 1 an
+d 2 of each
# object as referenced hash keys, with field 3 as value
my %headers;
my $current_header = 0;
foreach(@f1){
# match headers
if(/(\|.*){8}/){
$current_header = $_;
}
# match objects and add to %header (which will be a hash of hashes)
# with 3rd object field as value
if(/^((?:\|\d+){2})\|(\d+)$/ and $current_header){
${$headers{$current_header}}{$1} = $2;
}
}
$current_header = 0;
foreach(@f2){
# match headers
if(/(\|.*){8}/){
$current_header = $_;
}
# match objects and add to %header (which will be a hash of hashes)
# with 3rd object field as value
if(/^((?:\|\d+){2})\|(\d+)$/ and $current_header){
if(defined $headers{$current_header} and defined ${$headers{$curre
+nt_header}}{$1}){
${$headers{$current_header}}{$1} += $2;
}
}
}
# output the results...
foreach my $hkey(keys %headers){
print "Header $hkey\n";
foreach my $okey(keys %{$headers{$hkey}}){
print "Object $okey total:" . ${headers{$hkey}}{$okey} . "\n";
}
}
__DATA__
f1
#LOGNUM|1|OPERATIONAL
|O%:CCLN-1-CBS1
|8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6
|7|1|1553
|7|2|13
|7|3|1870
|5|4|0
|7|5|22087238
|7|6|73162814
|8.2.0.4352.1.2|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6
|7|1|1
|7|2|2
|7|3|3
|5|4|4
|7|5|5
|7|6|6
f2
#LOGNUM|1|OPERATIONAL
|O%:CCLN-1-CBS1
|8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6
|7|1|1545
|7|2|14
|7|3|1981
|5|4|0
|7|5|18613745
|7|6|81837527
|8.2.0.4352.1.2|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6
|7|1|10
|7|2|20
|7|3|30
|5|4|40
|7|5|50
|7|6|60
Note that you will have to add file-input (currently reading sample data from <DATA>)
map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2
-$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
Tom Melly, pm@tomandlu.co.uk
|