Problem with Range Operator sequence number - Perl

This is a discussion on Problem with Range Operator sequence number - Perl ; 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"); ...

+ Reply to Thread
Results 1 to 2 of 2

Problem with Range Operator sequence number

  1. Default 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

  2. Default Re: Problem with Range Operator sequence number

    Paul.Porcelli@aggreko.co.uk (Paul Porcelli) wrote in message news:<4384f73c.0407140741.12bede1c@posting.google.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 to Thread

Similar Threads

  1. Replies: 4
    Last Post: 12-14-2007, 08:07 AM
  2. sequence number problem in visual basic 6.0
    By Application Development in forum basic.visual
    Replies: 19
    Last Post: 09-12-2007, 03:24 PM
  3. Random number in a range - speed problem
    By Application Development in forum C
    Replies: 6
    Last Post: 07-30-2007, 10:22 PM
  4. cout, operator<<, sequence points
    By Application Development in forum c++
    Replies: 5
    Last Post: 07-23-2007, 06:45 PM
  5. Problem with Range Operator sequence number
    By Application Development in forum Perl
    Replies: 3
    Last Post: 07-15-2004, 09:41 PM