Try this:

Caveat: This all assumes LOTS about the format of your data being
consistent, and so should be treated as a "quick and dirty" as opposed to
anything resembling a robust application...  I'm not sure what your
intention with the script is, but is worth mentioning.

-Tom Kinzer

__SNIP__

my $input  = '/appl/log/200301130.txt';
my $total;
die "Usage: Arg1: Input File to Scan."
    unless $input;

open IN, "< $input" or die "Unable to open $input for reading, $!, stopped";


while ( <IN> ) {
        if ( /  Document Format/ ) { last };
}

while ( <IN> ) {
        if ( /  Total:                         -------------/ ) { last };
}

while ( <IN> ) {
        if ( /^\s*\d+/ ) {
           chomp;
           s/\s*(\d+)\s*/$1/;
           $total = $_;
           printf "Total: %010s\n", $total;
           last;
        }
}

close IN;

__END__

-----Original Message-----
From: Katka a Daniel Dunajsky [mailto:[EMAIL PROTECTED]
Sent: Monday, December 08, 2003 12:15 PM
To: [EMAIL PROTECTED]
Subject: Reading a log file, again


Hello Tom,

I hope you are in a good time again, because I would like to ask you for
help – again.
The first script that you did send to me works well. The problem is that I
was not accurate with the situation description.
>From what I understand, your script looks for ‘Total:’ and then for
following line with numbers, reads them and prints them. That is what I
need. However, there are 3 sections with ‘Total:’ and I am interested only
in one of them. I was trying to solve this issue by modifying your script,
now it looks like this:

#!/usr/local/bin/perl -w
use strict;

my $input  = '/appl/log/200301130.txt';
my $total;
die "Usage: Arg1: Input File to Scan."
    unless $input;

open IN, "< $input" or die "Unable to open $input for reading, $!, stopped";

while ( defined(<IN>) ) {

        while ( <IN> ) {
                if ( /  Document Format/ ) { last };
        }

        while ( <IN> ) {
                if ( /  Total:                         -------------/ ) { last };
        }

        while ( <IN> ) {
                if ( /^\s*\d+/ ) {
            chomp;
                   s/\s*(\d+)\s*/$1/;
                   $total = $_;
                   printf "Total: %010s", $total;
                }
        }
}

close IN;

Your script without modification returns 3 values:
Total: 000052,497Total: 000049,670Total: 000049,670.
After the change I implemented it returns 2 values:
Total: 000049,670Total: 000049,670.
The section I am interested in (in the log file) starts with “  Document
Format” and then there is the “  Total:” and the number returned is the
first 49,670 returned after modification. The second number I am not
interested in and I don’t know how to limit script from continuing further
down. Could you please advice?

Thank you for your time.

danield

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=dept/features&pgmarket=en-ca&RU=http%3a%2f%2fjoin.
msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to