Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Adding object identifiers corresponding to matched headers and sub-headers.

by Melly (Hermit)
on Jan 19, 2007 at 23:30 UTC ( #595623=note: print w/ replies, xml ) Need Help??


in reply to Adding object identifiers corresponding to matched headers and sub-headers.

<update>I've fixed a potential bug since the original posting - btw you don't specify what should happen if the header+subheader+object only appears in one file (either file 1 or file 2) - currently, they will still be reported.</update>

Kiran, try the following code. A couple of things (since I can't believe that this will be the end of it).

  1. You have some lines that look like sub-headers, but the first set of digits is an ip address, not a simple numeric-string - how should these be treated?
  2. You haven't really specified your output format.

BTW I doubt I'm doing you any favours writing your code - I don't know whether you are over your head at school or in a job, but you're digging yourself in deeper. Unless you're in management, or training for management, in which case you're doing fine. That said, learn to write better specifications (unless you're shooting for the golden ring, and going for upper management).

Here's the latest code...

use strict; # change these to change your input and output files my $file_1 = 'File1.dat'; my $file_2 = 'File2.dat'; my $out_file = 'Output.dat'; my %headers; my ($current_header1,$current_header2) = (0,0); open(INPUT, $file_1)||die "Cannot open $file_1 for read:$!\n"; foreach(<INPUT>){ # match headers - we'll be a little fussy to avoid false positives if(/^((\|(\d+\.){5}\d+){2}(\|.+){2})\|\d+\|\d+\s*$/){ $current_header1 = $1; $current_header2 = 0; } elsif(/^((\|\d+){2})\s*$/ and $current_header1){ $current_header2 = $1; } elsif(/^((\|\d+){2})\|(\d+)\s*$/ and $current_header1 and $current_h +eader2){ $headers{$current_header1}{$current_header2}{$1} = $2; } } close INPUT||die "WTF? Couldn't close $file_1:$!\n"; $current_header1 = 0; $current_header2 = 0; open(INPUT, $file_2)||die "Cannot open $file_2 for read:$!\n"; foreach(<INPUT>){ # match headers - we'll be a little fussy to avoid false positives if(/^((\|(\d+\.){5}\d+){2}(\|.+){2})\|\d+\|\d+\s*$/){ $current_header1 = $1; $current_header2 = 0; } elsif(/^((\|\d+){2})\s*$/ and $current_header1){ $current_header2 = $1; } elsif(/^((\|\d+){2})\|(\d+)\s*$/ and $current_header1 and $current_h +eader2){ $headers{$current_header1}{$current_header2}{$1} += $2; } } # output the results... open(OUT, ">$out_file")||die "Cannot open $out_file for write:$!\n"; foreach my $hkey(keys %headers){ print OUT "Header $hkey\n"; foreach my $subkey(keys %{$headers{$hkey}}){ print OUT "Subheader $subkey\n"; foreach my $objkey(keys %{$headers{$hkey}{$subkey}}){ print OUT "Object $objkey total:" . ${headers{$hkey}{$subkey}{$o +bjkey}} . "\n"; } } }
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: Adding object identifiers corresponding to matched headers and sub-headers.
Select or Download Code
Re^2: Adding object identifiers corresponding to matched headers and sub-headers.
by jdporter (Canon) on Jan 19, 2007 at 23:52 UTC
    I doubt I'm doing you any favours writing your code

    You're certainly not doing PerlMonks any favors... which I would hope, at this point, would be of more concern to you.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight

      I'm not entirely sure how this impacts on PM in a negative way - can you elaborate?

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-20 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls