Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

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


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

You still don't explain where, e.g. |7|1|1553, comes from - I can't see those values in the input files. You refer to them as 'objects', but I have no idea what that means in this context...

Can you please explain how you derive these values - I might then be tempted to offer some help (although I will not write you a complete solution).

You would do a lot better if you at least posted some sort of attempt at coding this.

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^3: Adding object identifiers corresponding to each IP and printing them to O/P File.
Download Code
Re^4: Adding object identifiers corresponding to each IP and printing them to O/P File.
by Kiran Kumar K V N on Jan 11, 2007 at 13:39 UTC

    Hi Melly,

    Object or Message Object is data (in the Form |7|1|1553) in a Packet(a Networking Term). For eg:- |7|1|1553 is one Object. Similarly |7|5|18613745 is another Object and so on.

    Identifier is one of the component in the Message Object. For eg:- in the Object |7|1|1553, 7 is the first identifier, 1 is the second identifier and 1553 is the third identifier.

    There are 'N' number (N being a real number) of Message Objects (I have mentioned just 6) under the header in each of the 2 Files i.e. Test and Test1.

    Both these Files are Log Files which are already given to the user and the complete data format in both Files will look like as below :-

    1) In File 'Test' :-

    #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

    : :

    : :

    and so on ....

    2) In File 'Test1' :-

    #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

    : :

    : :

    and so on....

    ii) Our purpose is to add the identifiers of objects (ignoring the 1st and 2nd place identifiers which are always common and adding only the identifiers at the 3rd place), corresponding to each matched header like the following:-

    |7|1|1553 + |7|1|1545 = |7|1|3098

    |7|2|13 + |7|2|14 = |7|2|27

    |7|3|1870 + |7|3|1981 = |7|3|3851

    |5|4|0 + |5|4|0 = |5|4|0

    |7|5|22087238 + |7|5|22087238 = |7|5|44174476

    |7|6|73162814 + |7|6|81837527 = |7|6|155000341

    The rest of the details, I have already explained in my previous posting.

    Request you to please give your very valuable Inputs.

    Thanks and Regards,

    KiranKumar K.

      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
      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

        Hi Shigetsu,

        But what about comparing each and every header in both the files and matching them. For eg.:- on sorting both Files and comparing the headers, found that only |8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6, matches completely.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-07-22 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (127 votes), past polls