in reply to Loop problem: jumps one record
Each of the 2 lines where you test against the regex is reading another record. Don't do that. Instead, you could store the record in a variable and then do the two tests on that one variable. eg:
use strict; use warnings; my $ip = ""; while (<>) { if (/Relay.access.denied/) { my $rec; do { $rec = <>; print "$2\n" if $rec =~ /(\d+)\s+(\S+)/; $ip = $2; } until ($rec !~ /(\d+)\s+(\S+)/); } }
However, there are so many other ways to approach this too. It would be better to avoid the regex duplication in the first place, for example.
Addendum: As you appear to be trying to parse the output of pflogsumm, perhaps this is an XY problem?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Loop problem: jumps one record
by math&ing001 (Novice) on Jan 31, 2017 at 12:05 UTC | |
by hippo (Archbishop) on Jan 31, 2017 at 13:43 UTC |