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