Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > 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
 
 
 
 
Chris Charley
Guest
Posts: n/a
 
      07-14-2004
(Paul Porcelli) wrote in message news:<. com>...
> 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 ?


Its difficult for me to quite understand the problem correctly, but
what I think you are asking is you want to push all the lines in
@lines immediately following the first range and the last one before
the end of the range. Richard Gration has posted one way to do this.

However, your start and end regexes will never match your text the way
they are now.

/\QVolume vol[1-2] verification started\E/
^ ^
You need to precede and end the regex with \Q and \E to escape the
brackets or else, simply backslah the brackets, '\[1-2\]', because
perl thinks they define a character class otherwise.

Chris
 
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-16-2004 02:41 AM
Problem with Range Operator sequence number Paul Porcelli Perl Misc 7 07-15-2004 02:25 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