Danield wrote:
>
> I am looking for help with creating a digest of a log file. I have found
> a nice tutorial that should help on
> http://www.pageresource.com/cgirec/ptut14.htm. However, this tutorial
> expects to have values in list separated by |   :
>
> he Rock|Cheer|Rock Bottom
> Triple H|Boo|Pedigree
> Stone Cold|Cheer|Stone Cold Stunner
>
> And I do have a log file, that looks like:
>
> ...
> Format count
> a 100
> b 51
> c 130
> d   5
> e   6
> Total: ---
> 292
> ...
>
> And I need to go through that log and find that 292 and store it into
> variable. If it was something like 'total: 292', I might be able to do it,
> however the value is on completely new line and nothing precedes it.
>
> Is anyone willing to help me?
>
> I am a completely newbie in programming.

First you need to be able to read from a file, but since that
part isn't the substance of the question, let's just assume that
your data is coming in on the STDIN filehandle. The following
should be partly self-explanatory. Keep reading lines from STDIN
until we find a line containing 'Total:'. Read the next line into
$total and exit the loop. (Beware that $total will then contain
the entire record, including the trailing newline character. It
may well need more massaging before you can use it.)

  my $total;
  while (<STDIN>) {
    if (/Total:/) {
      $total = <STDIN>;
      last;
    }
  }

HTH,

Rob



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