in reply to Re^3: 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.

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on Re^4: Adding object identifiers corresponding to each IP and printing them to O/P File.

Replies are listed 'Best First'.
Re^5: Adding object identifiers corresponding to each IP and printing them to O/P File.
by Melly (Chaplain) on Jan 11, 2007 at 14:46 UTC

    I have some code that, afaik, does what you want - however, I ain't posting it until I see some sort of coding effort from you - specifically:

    1. Some attempt to read both files
    2. Some attempt to perform a regex to recognise your headers and objects
    3. Some attempt to sum the final object field where appropriate

    Your code needn't work or, indeed, even run, but it should demonstrate good faith on your part...

    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
Re^5: Adding object identifiers corresponding to each IP and printing them to O/P File.
by shigetsu (Hermit) on Jan 11, 2007 at 15:14 UTC
    records.pl:
    #!/usr/bin/perl use strict; use warnings; my (@objects, @sets, @unsorted_records, @headers, %have_header, $resul +ts); foreach my $file (sort glob("./records*.dat")) { open(my $fh, '<', $file) or die "$file: $!\n"; my @items = <$fh>; close($fh); push @sets, \@items; } my $i = 0; foreach my $set (@sets) { foreach my $record (@$set) { next if $record =~ /^#/; chomp($record); my @ids = split m!\|!, $record; shift @ids; if (@ids > 3) { $have_header{$record}++; push @headers, $record if $have_header{$record} >= 2; } next unless @ids == 3; $objects[$i]->{$ids[0]}{$ids[1]} = $ids[2]; } $i++; } for (my $i = 0; $i < @objects; $i++) { foreach my $record (keys %{$objects[$i]}) { foreach my $item (keys %{$objects[$i]->{$record}}) { $results->{$record}{$item} += $objects[$i]->{$record}{$ite +m}; } } } foreach my $record (keys %$results) { foreach my $item (sort { $a <=> $b } keys %{$results->{$record}}) +{ my $new_record = "|$record|$item|$results->{$record}{$item}"; push @unsorted_records, $new_record; } } my @sorted_records = sort { (split m!\|!, $a)[2] <=> (split m!\|!, $b) +[2] } @unsorted_records; local $" = "\n"; print "@headers", @headers ? "\n" : ''; print "@sorted_records", @sorted_records ? "\n" : '';
    records1.dat:
    #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
    records2.dat:
    #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
    __OUTPUT__
    |8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6 |7|1|3098 |7|2|27 |7|3|3851 |5|4|0 |7|5|40700983 |7|6|155000341
    A reply falls below the community's threshold of quality. You may see it by logging in.