Trying to account for all the quirks of the calendar is very tricky business. That is why there are so many CPAN modules which will do this for you, Date::Calc, for example. You should seriously consider replacing your find_diff sub with something tried and tested from CPAN.

use warnings; use strict;

Check the success of open, use its 3-argument form and use lexical filehandles, $fh:

open my $fh, '<', $File or die "can not open $File: $!"; while (<$fh>) { ... } close $fh;

This:

if ( $_ =~ /([0-9]+\:[0-9]+\:[0-9]+) ([0-9]+) (\w+) (\w+) (\w+)/ ){

is more concisely written as this:

if (/(\d+:\d+:\d+) (\d+) (\w+) (\w+) (\w+)/ ){

Update: OK, I'm back in from shoveling snow. You should choose a better name for your hash data structure than %hash. I dont think you need all those extra variables, just stuff them into your hash right away.

use strict; use warnings; my %hash; my $File = "input.txt"; open my $fh, '<', $File or die "can not open $File: $!"; while (<$fh>) { chomp; ## taking time, transaction id, status, transaction name and amoun +t. if (/(\d+:\d+:\d+) (\d+) (\w+) (\w+) (\w+)/ ){ $hash{$2} = [($3, $1, $4, $5)]; } ## If the status is stop.. elsif (/(\d+:\d+:\d+) (\d+) (\w)/ ) { $hash{$2}->[0] = $3; my $difftime = find_diff($hash{$2}->[1], $1); $hash{$2}->[1] = $difftime; print "Transaction id $2 name $hash{$2}->[2] Amount $hash{$2}- +>[3] Duration $hash{$2}->[1]\n"; # If the transaction is stopped initialising the values. delete $hash{$2}; } } close $fh; print "============================================\n"; ## to print the transaction started but not yet stopped for my $id ( keys %hash ) { if ( $hash{$id}->[0] =~ /start/i ) { print "Transaction with id $id is started but not yet stopped\ +n"; } }

In reply to Re: parsing and get the report by toolic
in thread parsing and get the report by perlthirst

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.