Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^9: Adding object identifiers corresponding to each IP and printing them to O/P File.

by Melly (Hermit)
on Jan 12, 2007 at 13:32 UTC ( #594381=note: print w/ replies, xml ) Need Help??


in reply to Re^8: Adding object identifiers corresponding to each IP and printing them to O/P File.
in thread Adding object identifiers corresponding to each IP and printing them to O/P File.

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


Comment on Re^9: Adding object identifiers corresponding to each IP and printing them to O/P File.
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://594381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-02 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls