is there a way to tell <> to go back one line at the end of the loop is the wrong question agent Spooner..

Why you want to force an iterator to go back?

Another approach is better: something is true after Relay access denied is encountered and become false when Sender address rejected is reached (hoping thi is your case).

Perl offer you a funny named flip-flop operator (see my recent post about it for links and explaination).

The following short program it is nothing more that: if we are between a START and STOP sentence, print the IP if you find an IP.

use strict; use warnings; while (<DATA>){ if (/^Relay access denied/ .. /Sender address rejected/){ print "$2\n" if $_ =~ /(\d+)\s+(\S+)/; } } __DATA__ Relay access denied (total: 2) 1 111.111.111.111 1 222.222.222.222 1 333.333.333.333 Sender address rejected: Access denied (total: 50) 1 200.200.200.200 Relay access denied (total: 1) 1 255.255.255.255 Sender address rejected: Access denied (total: 50) ##OUTPUT 111.111.111.111 222.222.222.222 333.333.333.333 255.255.255.255

As you posted as anonymous your first post i missed the opportunity to express you a warm welcome to the monastery and to the wonderful world of Perl math&ing001 !

In addition the special token DATA is very useful to embed some data example to your program: it is described in perldata in the section Special Literals

Regexp::Common::net is a convenient module to match IPs: you see above the regex match 333.333.333.333 as valid IP. As side note do not put real IP data on the Net: use always fake one as iI did.

L*

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^3: Loop problem: jumps one record (updated) by Discipulus
in thread Loop problem: jumps one record by Anonymous Monk

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.