Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem with Range Operator sequence number

Reply
Thread Tools

Problem with Range Operator sequence number

 
 
Paul Porcelli
Guest
Posts: n/a
 
      07-14-2004
I have the following code(excerpt) which grabs some lines from a
syslog
file and adds any found in the range to an array.

@lines=();@vvlines=();
$t = new Net::Telnet (Timeout => 30, Prompt => '/<\d+\>/');
$t->open($t3);
$t->login($username, $passwd);
@lines=$t->cmd("tail -1000 syslog");
$t->close;
foreach (@lines) {
push(@vvlines,$_) if /Volume vol[1-2] verification started/ ..
/Volume vol[1-2] verification ended/;
}

This piece of code is part of a foreach loop which iterates two times.
I have a problem with the following situation:

Pass 1 of the foreach finds the left side of the range but never finds
the right side. This means that the range operator is still true.

Pass 2 of the foreach now pushes all the lines onto the vvlines array
as the range operator is still true. This is not desired. I only want
to push the lines after the left side is matched.

How do I reset the range operator to false between each iteration of
the foreach loop ?

Many thanks.

Paul Porcelli
 
Reply With Quote
 
 
 
 
John J. Trammell
Guest
Posts: n/a
 
      07-14-2004
[nonexistent comp.lang.perl newsgroup removed]

On 14 Jul 2004 08:41:49 -0700, Paul Porcelli wrote:
> I have the following code(excerpt) which grabs some lines from a
> syslog file and adds any found in the range to an array.
>
> @lines=();@vvlines=();
> $t = new Net::Telnet (Timeout => 30, Prompt => '/<\d+\>/');
> $t->open($t3);
> $t->login($username, $passwd);
> @lines=$t->cmd("tail -1000 syslog");
> $t->close;
> foreach (@lines) {
> push(@vvlines,$_) if /Volume vol[1-2] verification started/ ..
> /Volume vol[1-2] verification ended/;
> }


Not sure what you're expecting the [1-2] to do here. Why not use [12]?
Or are you expecting to match the literal string "1-2"?

Oh, and make sure you "use strict".

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      07-15-2004
Paul Porcelli <> wrote in comp.lang.perl.misc:
> I have the following code(excerpt) which grabs some lines from a
> syslog
> file and adds any found in the range to an array.
>
> @lines=();@vvlines=();
> $t = new Net::Telnet (Timeout => 30, Prompt => '/<\d+\>/');
> $t->open($t3);
> $t->login($username, $passwd);
> @lines=$t->cmd("tail -1000 syslog");
> $t->close;
> foreach (@lines) {
> push(@vvlines,$_) if /Volume vol[1-2] verification started/ ..
> /Volume vol[1-2] verification ended/;
> }
>
> This piece of code is part of a foreach loop which iterates two times.
> I have a problem with the following situation:
>
> Pass 1 of the foreach finds the left side of the range but never finds
> the right side. This means that the range operator is still true.
>
> Pass 2 of the foreach now pushes all the lines onto the vvlines array
> as the range operator is still true. This is not desired. I only want
> to push the lines after the left side is matched.
>
> How do I reset the range operator to false between each iteration of
> the foreach loop ?


Make sure the second condition becomes true at the end of the file.
Untested:

/Volume vol[1-2] verification started/ ..
( /Volume vol[1-2] verification ended/ || eof);

The parentheses around the second operand may be unnecessary.

Anno
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      07-15-2004
Paul Porcelli <> wrote in comp.lang.perl.misc:
> I have the following code(excerpt) which grabs some lines from a
> syslog
> file and adds any found in the range to an array.
>
> @lines=();@vvlines=();
> $t = new Net::Telnet (Timeout => 30, Prompt => '/<\d+\>/');
> $t->open($t3);
> $t->login($username, $passwd);
> @lines=$t->cmd("tail -1000 syslog");
> $t->close;
> foreach (@lines) {
> push(@vvlines,$_) if /Volume vol[1-2] verification started/ ..
> /Volume vol[1-2] verification ended/;
> }
>
> This piece of code is part of a foreach loop which iterates two times.
> I have a problem with the following situation:
>
> Pass 1 of the foreach finds the left side of the range but never finds
> the right side. This means that the range operator is still true.
>
> Pass 2 of the foreach now pushes all the lines onto the vvlines array
> as the range operator is still true. This is not desired. I only want
> to push the lines after the left side is matched.


Your question would have been much clearer if yuo had actually *shown*
the outer loop, together with a set of data that throws ".." out of
sync.

The code you posted doesn't show your problem, so you got a few replies
that don't address your problem.

> How do I reset the range operator to false between each iteration of
> the foreach loop ?


Make sure the second condition becomes true at the end of the file.
Untested:

/Volume vol[1-2] verification started/ ..
( /Volume vol[1-2] verification ended/ || eof);

The parentheses around the second operand may be unnecessary.

Anno
 
Reply With Quote
 
Paul Porcelli
Guest
Posts: n/a
 
      07-15-2004
Purl Gurl <> wrote in message news:<>...
> Paul Porcelli wrote:
>
> > /Volume vol[1-2] verification started/ .. /Volume vol[1-2] verification ended/;

>
> > Pass 1 of the foreach finds the left side of the range but never finds
> > the right side. This means that the range operator is still true.

>
> > How do I reset the range operator to false between each iteration of
> > the foreach loop ?

>
> /Volume vol[1-2] verification started/ ... /Volume vol[1-2] verification ended/;
>
>
> Try using three periods instead of two periods.
>
> You do not provide enough precise information about your
> data to fully assess what you are doing.
>
>
> Purl Gurl



First pass @lines has the following

Blah Blah Blah
Volume vol1 verification started
Useful Data
Useful Data

So, it finds the start of the range but not the end.
That is OK as I want all that data
=======================

Second pass , @lines has info from another syslog file i.e.
Blah Blah Blah
Volume vol1 verification started
Useful Data
Useful Data
Volume vol1 verification ended

What I would like to happen here, is for that first value(Blah etc) to
be ignored. i.e. I want the range check to start from scratch again.
It doesn't though. It pulls out that first line(Blah etc) as well.
As I understand it, that is because the end of the range was never
detected during the first pass. So what I need is some way for the
range operator
to think the end of the range was found at the end of the first pass.

HTH
Paul
 
Reply With Quote
 
Paul Porcelli
Guest
Posts: n/a
 
      07-15-2004
Purl Gurl <> wrote in message news:<>...
> Paul Porcelli wrote:
>
> > /Volume vol[1-2] verification started/ .. /Volume vol[1-2] verification ended/;

>
> > Pass 1 of the foreach finds the left side of the range but never finds
> > the right side. This means that the range operator is still true.

>
> > How do I reset the range operator to false between each iteration of
> > the foreach loop ?

>
> /Volume vol[1-2] verification started/ ... /Volume vol[1-2] verification ended/;
>
>
> Try using three periods instead of two periods.
>
> You do not provide enough precise information about your
> data to fully assess what you are doing.
>
>
> Purl Gurl



First pass @lines has the following

Blah Blah Blah
Volume vol1 verification started
Useful Data
Useful Data

So, it finds the start of the range but not the end.
That is OK as I want all that data
=======================

Second pass , @lines has info from another syslog file i.e.
Blah Blah Blah
Volume vol1 verification started
Useful Data
Useful Data
Volume vol1 verification ended

What I would like to happen here, is for that first value(Blah etc) to
be ignored. i.e. I want the range check to start from scratch again.
It doesn't though. It pulls out that first line(Blah etc) as well.
As I understand it, that is because the end of the range was never
detected during the first pass. So what I need is some way for the
range operator
to think the end of the range was found at the end of the first pass.

HTH
Paul
 
Reply With Quote
 
Brad Baxter
Guest
Posts: n/a
 
      07-15-2004
On Thu, 15 Jul 2004, Purl Gurl wrote:
>
> for (@lines)
> {
> if ($_ =~ /Volume vol[12] verification started(.*)Volume vol[12] verification ended/s)
> { push(@vvlines, $1); }
> }


Forgive me for mentioning it, but following are alternative ways of saying
that:

for (@lines)
{
if (/Volume vol[12] verification started(.*)Volume vol[12] verification ended/s)
{ push(@vvlines, $1); }
}

for (@lines)
{
push(@vvlines, $1)
if /Volume vol[12] verification started(.*)Volume vol[12] verification ended/s
}

for (@lines)
{
/Volume vol[12] verification started(.*)Volume vol[12] verification ended/s
&& push(@vvlines, $1);
}

for (@lines)
{
/Volume vol[12] verification started(.*)Volume vol[12] verification ended/s
and push(@vvlines, $1);
}


Regards,

Brad
 
Reply With Quote
 
Eric Amick
Guest
Posts: n/a
 
      07-16-2004
On 15 Jul 2004 10:54:39 GMT, (Anno
Siegel) wrote:

>Make sure the second condition becomes true at the end of the file.
>Untested:
>
> /Volume vol[1-2] verification started/ ..
> ( /Volume vol[1-2] verification ended/ || eof);
>
>The parentheses around the second operand may be unnecessary.


They aren't, but this is definitely a time when expecting people to know
the difference in precedence is a Bad Idea.

--
Eric Amick
Columbia, MD
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to iterate over sequence and non-sequence ? stef mientki Python 13 10-20-2007 10:21 AM
Problem with Range Operator sequence number Paul Porcelli Perl 3 07-16-2004 02:41 AM
Problem with Range Operator sequence number Paul Porcelli Perl Misc 7 07-15-2004 02:25 PM
Problem with Range Operator sequence number Paul Porcelli Perl 1 07-14-2004 10:52 PM
BOOT SEQUENCE (how to change boot sequence) bird Computer Support 13 12-24-2003 02:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57