[30471] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1714 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 12 14:09:47 2008

Date: Sat, 12 Jul 2008 11:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 12 Jul 2008     Volume: 11 Number: 1714

Today's topics:
    Re: empty first element after split <tadmc@seesig.invalid>
        How can I use constants? <bill@ts1000.us>
    Re: How can I use constants? <bill@ts1000.us>
    Re: How can I use constants? <bill@ts1000.us>
    Re: How can I use constants? <smallpond@juno.com>
        Is this possible in Perl? <bill@ts1000.us>
    Re: Is this possible in Perl? (Jens Thoms Toerring)
    Re: Is this possible in Perl? (Randal L. Schwartz)
    Re: Is this possible in Perl? <bill@ts1000.us>
    Re: Is this possible in Perl? <bill@ts1000.us>
    Re: Is this possible in Perl? (Jens Thoms Toerring)
        remove previous lines of a log file <sivarajesh.jarugula@gmail.com>
    Re: remove previous lines of a log file (Jens Thoms Toerring)
    Re: remove previous lines of a log file <daveb@addr.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 12 Jul 2008 07:14:24 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: empty first element after split
Message-Id: <slrng7h810.9f9.tadmc@tadmc30.sbcglobal.net>

Michael Hamer <mh_usenet@gmx.de> wrote:


>      my @fields = split /^([^:]+):\s*/m;
>      shift @fields;      # for leading null field

Others have answered your real question, but I'll point out
that those 2 lines can be replaced with:

    my(undef, @fields) = split /^([^:]+):\s*/m; # ignore leading null field


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Sat, 12 Jul 2008 05:57:10 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: How can I use constants?
Message-Id: <d93ba6ab-82c5-448f-a20a-f23097abd41f@f36g2000hsa.googlegroups.com>

I have an array that I want to reference the different items by a
constant instead of the actual value (quick code snippet example):

x_PLS = 0;
y_PLS = 1;
xscale_PLS = 2;
yscale_PLS = 3;
lock_PLS = 4;
constrain_PLS = 5;
useBW_PLS = 6;
transparency_PLS = 7;
dragx_PLS = 8;
dragy_PLS = 9;
dragwidth_PLS = 10;
dragheight_PLS = 11;
category_PLS = 12;
imagenumber_PLS = 13;
width_PLS = 14;
height_PLS = 15;
caption_PLS = 16;

@photoLayer = ();

 ... file the array from a file

$photoLayer[lock_PLS] = 1;

But perl seems to require that I make all my constants variables
($lock_PLS versus lock_PLS). Since these values are constant and will
not change, do I have to do this or am I missing a step?

Background reasoning for wanting to do this, my Flash App uses the
same constants and I want to be able to cut / paste the latest
constant values from the actionscript into the perl code and not have
to maintain 2 different versions of the same file (one with "$" before
the constant name, one without).

Bill H


------------------------------

Date: Sat, 12 Jul 2008 06:00:31 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: How can I use constants?
Message-Id: <85a8c357-6fa9-444f-b8bb-c17b2febfd87@l64g2000hse.googlegroups.com>

On Jul 12, 8:57=A0am, Bill H <b...@ts1000.us> wrote:
> I have an array that I want to reference the different items by a
> constant instead of the actual value (quick code snippet example):
>
> x_PLS =3D 0;
> y_PLS =3D 1;
> xscale_PLS =3D 2;
> yscale_PLS =3D 3;
> lock_PLS =3D 4;
> constrain_PLS =3D 5;
> useBW_PLS =3D 6;
> transparency_PLS =3D 7;
> dragx_PLS =3D 8;
> dragy_PLS =3D 9;
> dragwidth_PLS =3D 10;
> dragheight_PLS =3D 11;
> category_PLS =3D 12;
> imagenumber_PLS =3D 13;
> width_PLS =3D 14;
> height_PLS =3D 15;
> caption_PLS =3D 16;
>
> @photoLayer =3D ();
>
> ... file the array from a file
>
> $photoLayer[lock_PLS] =3D 1;
>
> But perl seems to require that I make all my constants variables
> ($lock_PLS versus lock_PLS). Since these values are constant and will
> not change, do I have to do this or am I missing a step?
>
> Background reasoning for wanting to do this, my Flash App uses the
> same constants and I want to be able to cut / paste the latest
> constant values from the actionscript into the perl code and not have
> to maintain 2 different versions of the same file (one with "$" before
> the constant name, one without).
>
> Bill H

As a follow up to my own post per perldoc it appears I have to use the
following format to set a constant:

use constant lock_PLS =3D> 1;

If that is the case then I guess my cut / paste method could work, I
would just have to do a few find / replaces afterwards.

Bill H


------------------------------

Date: Sat, 12 Jul 2008 06:13:58 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: How can I use constants?
Message-Id: <e8fc649d-1f03-4534-bed9-a6ad5116e118@z72g2000hsb.googlegroups.com>

On Jul 12, 9:00=A0am, Bill H <b...@ts1000.us> wrote:
> On Jul 12, 8:57=A0am, Bill H <b...@ts1000.us> wrote:
>
>
>
>
>
> > I have an array that I want to reference the different items by a
> > constant instead of the actual value (quick code snippet example):
>
> > x_PLS =3D 0;
> > y_PLS =3D 1;
> > xscale_PLS =3D 2;
> > yscale_PLS =3D 3;
> > lock_PLS =3D 4;
> > constrain_PLS =3D 5;
> > useBW_PLS =3D 6;
> > transparency_PLS =3D 7;
> > dragx_PLS =3D 8;
> > dragy_PLS =3D 9;
> > dragwidth_PLS =3D 10;
> > dragheight_PLS =3D 11;
> > category_PLS =3D 12;
> > imagenumber_PLS =3D 13;
> > width_PLS =3D 14;
> > height_PLS =3D 15;
> > caption_PLS =3D 16;
>
> > @photoLayer =3D ();
>
> > ... file the array from a file
>
> > $photoLayer[lock_PLS] =3D 1;
>
> > But perl seems to require that I make all my constants variables
> > ($lock_PLS versus lock_PLS). Since these values are constant and will
> > not change, do I have to do this or am I missing a step?
>
> > Background reasoning for wanting to do this, my Flash App uses the
> > same constants and I want to be able to cut / paste the latest
> > constant values from the actionscript into the perl code and not have
> > to maintain 2 different versions of the same file (one with "$" before
> > the constant name, one without).
>
> > Bill H
>
> As a follow up to my own post per perldoc it appears I have to use the
> following format to set a constant:
>
> use constant lock_PLS =3D> 1;
>
> If that is the case then I guess my cut / paste method could work, I
> would just have to do a few find / replaces afterwards.
>
> Bill H- Hide quoted text -
>
> - Show quoted text -

Following up my follow up. That don't work. Perl doesn't balk on it,
but it seems it is a null value, since it always brings up the 1st
element in the array (element 0) when I do:

print $photoLayer[lock_PLS];

Unless I am totally missing the boat, it will probably be easier to
just do a search on the "var " in the text I bring in from
actionscript and replace it with a "$" and make them variables.

Think I will go yard sailing.

Bill H


------------------------------

Date: Sat, 12 Jul 2008 06:49:54 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: How can I use constants?
Message-Id: <d4c93587-1b5f-45af-849b-d4c4b1880638@56g2000hsm.googlegroups.com>

On Jul 12, 9:13 am, Bill H <b...@ts1000.us> wrote:
> On Jul 12, 9:00 am, Bill H <b...@ts1000.us> wrote:
>
>
>
> > On Jul 12, 8:57 am, Bill H <b...@ts1000.us> wrote:
>
> > > I have an array that I want to reference the different items by a
> > > constant instead of the actual value (quick code snippet example):
>
> > > x_PLS = 0;
> > > y_PLS = 1;
> > > xscale_PLS = 2;
> > > yscale_PLS = 3;
> > > lock_PLS = 4;
> > > constrain_PLS = 5;
> > > useBW_PLS = 6;
> > > transparency_PLS = 7;
> > > dragx_PLS = 8;
> > > dragy_PLS = 9;
> > > dragwidth_PLS = 10;
> > > dragheight_PLS = 11;
> > > category_PLS = 12;
> > > imagenumber_PLS = 13;
> > > width_PLS = 14;
> > > height_PLS = 15;
> > > caption_PLS = 16;
>
> > > @photoLayer = ();
>
> > > ... file the array from a file
>
> > > $photoLayer[lock_PLS] = 1;
>
> > > But perl seems to require that I make all my constants variables
> > > ($lock_PLS versus lock_PLS). Since these values are constant and will
> > > not change, do I have to do this or am I missing a step?
>
> > > Background reasoning for wanting to do this, my Flash App uses the
> > > same constants and I want to be able to cut / paste the latest
> > > constant values from the actionscript into the perl code and not have
> > > to maintain 2 different versions of the same file (one with "$" before
> > > the constant name, one without).
>
> > > Bill H
>
> > As a follow up to my own post per perldoc it appears I have to use the
> > following format to set a constant:
>
> > use constant lock_PLS => 1;
>
> > If that is the case then I guess my cut / paste method could work, I
> > would just have to do a few find / replaces afterwards.
>
> > Bill H- Hide quoted text -
>
> > - Show quoted text -
>
> Following up my follow up. That don't work. Perl doesn't balk on it,
> but it seems it is a null value, since it always brings up the 1st
> element in the array (element 0) when I do:
>
> print $photoLayer[lock_PLS];
>
> Unless I am totally missing the boat, it will probably be easier to
> just do a search on the "var " in the text I bring in from
> actionscript and replace it with a "$" and make them variables.
>
> Think I will go yard sailing.
>
> Bill H


perl -e '@f=(0, 1, 2, 3); use constant two => 2; print $f[two]'
2

I think your boat must have sailed.  Also, you shouldn't be
cutting and pasting, there's a pretty good text processing
language for doing that kind of thing.  I'll remember its name
in a second.  Maybe you could store the values in a hash
instead and use the names as keys?

--S


------------------------------

Date: Sat, 12 Jul 2008 05:09:53 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Is this possible in Perl?
Message-Id: <93920bb1-09af-4187-8376-6e8c2cc79211@m44g2000hsc.googlegroups.com>

(sorry about the subject, didn't know how to word the question without
putting the whole message in the subject)

I have a perl routine that takes some html form variables that are
"POST"ed to it from a Flash app (works the same as a web page POST)
and when it is done it sends back a status to the Flash program using
a simple:

            print "Content-type:text/plain\n\n";
            print "status=complete";
            exit;

which works fine. What I would like to do is send the above so that
the Flash app goes about its business but have the perl program
continue on doing some stuff that I don't want the user to have to
wait for the completion of. What I am looking for is a way to simulate
whatever perl does for the waiting user when it performs the exit
without exiting. Something like this:

            print "Content-type:text/plain\n\n";
            print "status=complete";
            "some magical perl command to force the above to the user
and end connection without stopping program"

            additional code that is executed
            exit;

Any clues, perldocs -f, online docs would be appreciated.

Bill H


------------------------------

Date: 12 Jul 2008 15:25:29 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Is this possible in Perl?
Message-Id: <6ds0n9F42njfU1@mid.uni-berlin.de>

Bill H <bill@ts1000.us> wrote:
> I have a perl routine that takes some html form variables that are
> "POST"ed to it from a Flash app (works the same as a web page POST)
> and when it is done it sends back a status to the Flash program using
> a simple:
>
>             print "Content-type:text/plain\n\n";
>             print "status=complete";

Perhaps things will already work when you append a "\n" to that
last line? It could happen that a line without a trailing new-
line gets stuck in some internal buffers and only gets send to
the parent process when your script exits and all open files are
closed after the buffers are flushed. Or do

$| = 1;

to make sure stdout is unbuffered.

>             exit;
>
> which works fine. What I would like to do is send the above so that
> the Flash app goes about its business but have the perl program
> continue on doing some stuff that I don't want the user to have to
> wait for the completion of. What I am looking for is a way to simulate
> whatever perl does for the waiting user when it performs the exit
> without exiting. Something like this:

>             print "Content-type:text/plain\n\n";
>             print "status=complete";
>             "some magical perl command to force the above to the user
> and end connection without stopping program"
>
>             additional code that is executed
>             exit;

If appending a newline to the last line of ouput or setting
auto-flushing for stdout doesn't do the job I guess it's only
in parts a Perl issue and involves also the behaviour of the
process that started the Perl script. The question is: is what
the process that started your script waiting for. Is it waiting
for the stdout of yor script to become closed or is it waiting
for your script to exit? That would seem to me the most likely
scenarios. Thus you could try to do what that process is waiting
for, i.e. in the first case close stdout (and perhaps stderr)
and in the second fork() (to get a new process) and exit in the
parent process. I would try something like this:

   close STDIN;
   close STDERR;
   exit 0 if fork;

The first two lines close stdin and stderr, just to make sure
all buffers are flushed, and the last one ends the parent pro-
cess while creating a new process for continuing with whatever
you still may have to do. If that works you can try if leaving
out the fork() also works. (But note: that's from a UNIX per-
spective, I have no idea how things work under Windows..)

                            Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Sat, 12 Jul 2008 08:58:48 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Is this possible in Perl?
Message-Id: <86hcavqekn.fsf@blue.stonehenge.com>

>>>>> "Bill" == Bill H <bill@ts1000.us> writes:

Bill>             print "Content-type:text/plain\n\n";

Ignoring the rest of your message, this is an invalid header.  Please ensure
that you have a space after the colon.  Sure, some browsers error-correct for
your mistake, but it's best to simply do it right, in case some new browser
doesn't perform the same error correction.

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


------------------------------

Date: Sat, 12 Jul 2008 10:28:10 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Is this possible in Perl?
Message-Id: <2cc98aff-8979-412f-b4a2-f77f74b6555d@e53g2000hsa.googlegroups.com>

On Jul 12, 11:25=A0am, j...@toerring.de (Jens Thoms Toerring) wrote:
> Bill H <b...@ts1000.us> wrote:
> > I have a perl routine that takes some html form variables that are
> > "POST"ed to it from a Flash app (works the same as a web page POST)
> > and when it is done it sends back a status to the Flash program using
> > a simple:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 print "Content-type:text/plain\n\n";
> > =A0 =A0 =A0 =A0 =A0 =A0 print "status=3Dcomplete";
>
> Perhaps things will already work when you append a "\n" to that
> last line? It could happen that a line without a trailing new-
> line gets stuck in some internal buffers and only gets send to
> the parent process when your script exits and all open files are
> closed after the buffers are flushed. Or do
>
> $| =3D 1;
>
> to make sure stdout is unbuffered.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 exit;
>
> > which works fine. What I would like to do is send the above so that
> > the Flash app goes about its business but have the perl program
> > continue on doing some stuff that I don't want the user to have to
> > wait for the completion of. What I am looking for is a way to simulate
> > whatever perl does for the waiting user when it performs the exit
> > without exiting. Something like this:
> > =A0 =A0 =A0 =A0 =A0 =A0 print "Content-type:text/plain\n\n";
> > =A0 =A0 =A0 =A0 =A0 =A0 print "status=3Dcomplete";
> > =A0 =A0 =A0 =A0 =A0 =A0 "some magical perl command to force the above t=
o the user
> > and end connection without stopping program"
>
> > =A0 =A0 =A0 =A0 =A0 =A0 additional code that is executed
> > =A0 =A0 =A0 =A0 =A0 =A0 exit;
>
> If appending a newline to the last line of ouput or setting
> auto-flushing for stdout doesn't do the job I guess it's only
> in parts a Perl issue and involves also the behaviour of the
> process that started the Perl script. The question is: is what
> the process that started your script waiting for. Is it waiting
> for the stdout of yor script to become closed or is it waiting
> for your script to exit? That would seem to me the most likely
> scenarios. Thus you could try to do what that process is waiting
> for, i.e. in the first case close stdout (and perhaps stderr)
> and in the second fork() (to get a new process) and exit in the
> parent process. I would try something like this:
>

Actually the Flash app isn't waiting for anything technically, just
the command in actionscript to post the values to the perl application
has a receive part thats stays active till somethign is received. If I
keep posting without any receiving back eventually you can end up with
a stack issue, so best practice is to send back the status=3Dcomplete
(btw if you add a trailing \n then flash doesn't like it - go figure).
I also may end up using that status=3Dcomplete for something else
(failure code, or information back to the application).

> =A0 =A0close STDIN;
> =A0 =A0close STDERR;
> =A0 =A0exit 0 if fork;
>
> The first two lines close stdin and stderr, just to make sure
> all buffers are flushed, and the last one ends the parent pro-
> cess while creating a new process for continuing with whatever
> you still may have to do. If that works you can try if leaving
> out the fork() also works. (But note: that's from a UNIX per-
> spective, I have no idea how things work under Windows..)
>

If I do this, do any variables declared before the exit 0 if fork
still remain (I would think so)?

Bill H

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Regards, Jens
> --
> =A0 \ =A0 Jens Thoms Toerring =A0___ =A0 =A0 =A0j...@toerring.de
> =A0 =A0\__________________________ =A0 =A0 =A0http://toerring.de



------------------------------

Date: Sat, 12 Jul 2008 10:28:52 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Is this possible in Perl?
Message-Id: <4fea26d3-329c-4fa9-a2d7-294c9e15206e@27g2000hsf.googlegroups.com>

On Jul 12, 11:58=A0am, mer...@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Bill" =3D=3D Bill H <b...@ts1000.us> writes:
>
> Bill> =A0 =A0 =A0 =A0 =A0 =A0 print "Content-type:text/plain\n\n";
>
> Ignoring the rest of your message, this is an invalid header. =A0Please e=
nsure
> that you have a space after the colon. =A0Sure, some browsers error-corre=
ct for
> your mistake, but it's best to simply do it right, in case some new brows=
er
> doesn't perform the same error correction.
>

You are right Randal, unfortunately Flash 9 likes its this way.

Bill H

> print "Just another Perl hacker,"; # the original
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 00=
95
> <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> Seehttp://methodsandmessages.vox.com/for Smalltalk and Seaside discussion



------------------------------

Date: 12 Jul 2008 17:49:00 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Is this possible in Perl?
Message-Id: <6ds94cF45199U1@mid.uni-berlin.de>

Bill H <bill@ts1000.us> wrote:
> On Jul 12, 11:25 am, j...@toerring.de (Jens Thoms Toerring) wrote:
> > Bill H <b...@ts1000.us> wrote:
> > > I have a perl routine that takes some html form variables that are
> > > "POST"ed to it from a Flash app (works the same as a web page POST)
> > > and when it is done it sends back a status to the Flash program using
> > > a simple:
> >
> > >             print "Content-type:text/plain
> > >             print "status=complete";
> >
> > Perhaps things will already work when you append a "\n" to that
> > last line? It could happen that a line without a trailing new-
> > line gets stuck in some internal buffers and only gets send to
> > the parent process when your script exits and all open files are
> > closed after the buffers are flushed. Or do

> Actually the Flash app isn't waiting for anything technically, just
> the command in actionscript to post the values to the perl application
> has a receive part thats stays active till somethign is received. If I
> keep posting without any receiving back eventually you can end up with
> a stack issue, so best practice is to send back the status=complete
> (btw if you add a trailing \n then flash doesn't like it - go figure).

Ok, so what about setting stdout to auto-flush

$| = 1;

to make sure the reading application actually gets that line
(or closing at least stdout)?

> I also may end up using that status=complete for something else
> (failure code, or information back to the application).

> >    close STDIN;

Sorry, that should have been

       close STDOUT;

> >    close STDERR;
> >    exit 0 if fork;

> If I do this, do any variables declared before the exit 0 if fork
> still remain (I would think so)?

Yes, you get a nearly exact copy of the parent process with
all variables intact. In most cases the only noticable dif-
ference is the return value of fork().

                              Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Sat, 12 Jul 2008 08:33:40 -0700 (PDT)
From: rajesh <sivarajesh.jarugula@gmail.com>
Subject: remove previous lines of a log file
Message-Id: <06366d09-3f85-4880-9378-1b30467366a3@26g2000hsk.googlegroups.com>

Hi,
      I need a parser logic in perl. I need to read a log file line by
line and search for a keyword. Once the keyword is found in any line,
I need to remove the previous two lines and current line. My new log
file, should not have these three lines.

Thanks in Advance
Rajesh


------------------------------

Date: 12 Jul 2008 16:24:12 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: remove previous lines of a log file
Message-Id: <6ds45cF437vvU1@mid.uni-berlin.de>

rajesh <sivarajesh.jarugula@gmail.com> wrote:
>       I need a parser logic in perl. I need to read a log file line by
> line and search for a keyword. Once the keyword is found in any line,
> I need to remove the previous two lines and current line. My new log
> file, should not have these three lines.

On most systems files are simply a sequence of bytes and you
can't cut out something from the middle. It's not like a deck
of cards, where each card is a line in the file, and where
you can pull out a few cards from the middle. You have to
copy everything from the old file to a new one (of course ex-
cept the bits you want to remove) and then replace the old
file by the new one. So in your case you have to keep three
lines in memory, writing the oldest one out if the newest
one does not contain the keyword you were looking for. Only
if it's in the newest line forget about the three lines and
copy all the rest of the contents of the old file to the new
one. Something like this should do:

#!/usr/bin/perl

use strict;
use warnings;

open my $in,  '<', 'log'     or die "Can't open log file.\n";
open my $out, '>', 'log.new' or die "Can't open replacement file.\n";

my @lines;
$lines[ 0 ] = <$in>;
$lines[ 1 ] = <$in>;

while ( <$in> ) {
    if ( /KEYWORD/ ) {
        while ( <$in> ) {
            print $out $_;
        }
        last;
    }
    print $out shift @lines;
    push @lines, $_;
}

close $out;
close $in;
rename 'log.new', 'log';

                                Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


------------------------------

Date: Sat, 12 Jul 2008 18:34:53 +0200
From: Dave B <daveb@addr.invalid>
Subject: Re: remove previous lines of a log file
Message-Id: <g5amen$lpi$1@registered.motzarella.org>

rajesh wrote:

> Hi,
>       I need a parser logic in perl. I need to read a log file line by
> line and search for a keyword. Once the keyword is found in any line,
> I need to remove the previous two lines and current line. My new log
> file, should not have these three lines.
> 
> Thanks in Advance
> Rajesh

You don't say whether the keyword can appear multiple times, and if so, if
lines can be overlapping. I'll assume the keyword can appear multiple times,
but lines do not overlap, and the file has at least three lines.

A solution that reads the file line by line has already been given.
If you can afford to slurp the whole file, then

$f=~s/(?:.*\n){2}.*keyword.*\n//g;

should do what you want. (Note that the last line in the file should be
correctly terminated by a newline).

-- 
D.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1714
***************************************


home help back first fref pref prev next nref lref last post