in reply to Search after match in dynamic lines

Crossposted to StackOverflow. It's considered polite to inform about crossposting to prevent duplicate work of people not attending both the involved sites.

Please, use the <CODE> tags for the input files.

There's no line containing "^ Success" in your data. Do you mean qr/^ Success/?

Have you tried the flip-flop operator?

while (<>) { my $match = /^Success.*Id-/i ... /^Success/; print if $match && $match !~ /E/; }

Three dots are similar to two dots, but the second match isn't attempted for the first matching line. The last matching line of a block returns its number with E0 appended, so it numerically remains the same, but you can test it's the last line.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Search after match in dynamic lines
by haukex (Archbishop) on Sep 01, 2018 at 06:58 UTC

    If the Ids are unique this is of course a good solution, but if not this has a caveat... if there happen to be two Success sections with the same Id right after each other, the second one won't be matched unless the second regex is changed accordingly:

    use warnings; use strict; my $ID = '5678'; while (<DATA>) { my $match = /^Success.*Id-\Q$ID\E/i ... /^Success.*Id-(?!\Q$ID\E)/i; print if $match && $match !~ /E/; } __DATA__ One Success|Id-abcd Two Success|Id-1234 Three Success|Id-abcd Four Success|Id-5678 Five Success|Id-5678 Six Success|Id-9900 Seven Success|Id-5678 Eight Success|Id-0000 Nine