471,052 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,052 software developers and data experts.

Problem with Range Operator sequence number

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
Jul 19 '05 #1
3 4380
Paul Porcelli <Pa***********@aggreko.co.uk> 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
Jul 19 '05 #2
Paul Porcelli <Pa***********@aggreko.co.uk> 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
Jul 19 '05 #3
On 15 Jul 2004 10:54:39 GMT, an******@lublin.zrz.tu-berlin.de (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
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul Porcelli | last post: by
3 posts views Thread by Robert McGregor | last post: by
4 posts views Thread by Kamran K | last post: by
12 posts views Thread by tojigneshshah | last post: by
5 posts views Thread by tojigneshshah | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.