Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

RE: Multiple session log extraction from a single file problem

by nuance (Hermit)
on Aug 06, 2000 at 19:11 UTC ( #26430=note: print w/replies, xml ) Need Help??

in reply to Multiple session log extraction from a single file problem

I would localise the $/ variable and set it to the string that splits your log entries "*****\n*****". If you then read from the file in a scalar context it will give you one complete log entry.

You then need to remove the string you split the file on ("*****\n*****") and split the remainder on a new line "\n". Place the result of this split in an array. If the last element of this array starts with "Server Closed", then you have a complete log entry.

#!/usr/bin/perl -w use strict; my @status; { my ($log, @split_log, $status); local $/ = qq{*****\n*****}; while ($log = <DATA>) { $log =~ s/\Q*****\E\n\Q*****\E$//; @split_log = split "\n", $log; $status = ($split_log[$#split_log] =~ m/^Server Closed/) ? "complete\n" : "incomplete\n"; push @status, $status; } } __DATA__ ***** Server Started Monday data1 data2 Server Closed Tuesday ***** ***** Server Started Wednesday data3 data4 Server Closed Friday ***** ***** Server Started data5

This leaves the string "*****" on the front of the first log entry. You can then do whatever processing you need on the logs either one complete log at a time, or instead of assigning the split to @split_log, create an anonymous array and push that onto @split_log. This will let you defer your processing to the end.


Replies are listed 'Best First'.
RE: RE: Multiple session log extraction from a single file problem
by merlyn (Sage) on Aug 07, 2000 at 08:28 UTC

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2022-01-27 01:32 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.