Hello ovedpo15

Hoping i'm understandunding correctly the following statement:

> because there is no smaller number than 1234 and larger than 1220

You can use a switch (do something only if switch is on) and a yardstick/touchstone (do only if comparison gives something..). In loops generally exit condintions go first, but in this case the switch condition must be the first one, then all exit conditions as always.

use strict; use warnings; my $arg = 1220; my $switch; my @result; # here the touchstone or yardstick # start the comparison with a reasonably big number $result[0] = 10 ** 6; while (<DATA>){ $switch = 1 if /^Status\s+id.*name$/; next unless $switch; next if /^[\-]+$/; chomp; my @fields = split /\s+/; if ( $fields[1] =~ /^\d+$/ and $fields[1] > $arg and $fields[1] < + $result[0] ){ @result = @fields[1,0,-1]; } } # reset if nothing found undef @result unless $result[1]; print join ',',@result; __DATA__ date:17/4/2000 version: 4.1.0 -more info- -more info- ------------------------------------------------------------------ Status id not important info (two columns) name ----------------------------------------------------------------- Run 1234 @ ... foo1 Err 1235 @ ... foo1 Wait 54123 @ ... foo2 -----------------------------------------------------------------

L*

PS i add here to answer your below questions:

about do not start with a reasonable big number: know your data! is a very good principle. I cannot help here. You can use the biggest number perl can handle on you platform..

About the @fields[1,0,-1] it is an array slices. Note the Perl is happy within negative indexes so, as said in the CB but also here for posterity, means the second, the first and the last elements.

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Parsing output with a special format -- switch and yardstick by Discipulus
in thread Parsing output with a special format by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.