---->0702995-42.2017.8.01.0002 being the number i want to use to batch clean the document, keeping only the first time it found, completely wiping out the rest. [underlined emphases added]
I'm also confused by your OPed statement of requirements. I will concentrate on the above quoted section therefrom, so maybe something like:
(And in addition to an SSCCE, in future please also consider How to ask better questions using Test::More and sample data.)c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; my @lines = ( 'line 1 this line has no Foo number: keep', 'line 2 Foo something 1234-12.3 other 123 first valid keep', 'TOSS 3 Foo toss this 1234-12.3 line 123 DELETE', 'line 4 Foo not same 1234-12.3 offset 123 line keep', 'line 5 Foox not tag 1234-12.3 same offset 123 keep', 'line 6 has no Foo number: keep', 'line 7 Foo yyyy xxx 1234-12.3 this line keep', 'line 8 Foo xxxx zzzz 1234-12.4 different n keep', 'TOSS 9 Foo kill this 1234-12.3 one DELETE', 'line 10 no Foo number: keep', ); dd \@lines; print qq{\n}; ;; my $strange_n = qr{ (?<! \d) \d+ - \d+ (?: [.] \d+)* (?! \d) }xms; my $toss_tag = qr{ \b Foo \b }xms; ;; my $rx_can_toss = qr{ \A .+ $toss_tag \D* ($strange_n) }xms; ;; my ($valid_was_seen, $sn, $sn_offset); ;; my @keep_lines; LINE: for my $i (0 .. $#lines) { my ($sn_seen, $this_sn, $this_sn_offset) = map { $_ ? (1, $1, $-[1]) : () } $lines[$i] =~ $rx_can_toss ; if ($sn_seen) { if ($valid_was_seen) { next LINE if $sn eq $this_sn and $sn_offset eq $this_sn_offset; } else { ($valid_was_seen, $sn, $sn_offset) = (1, $this_sn, $this_sn_off +set); } } push @keep_lines, $lines[$i]; } dd \@keep_lines; " [ "line 1 this line has no Foo number: keep", "line 2 Foo something 1234-12.3 other 123 first valid keep", "TOSS 3 Foo toss this 1234-12.3 line 123 DELETE", "line 4 Foo not same 1234-12.3 offset 123 line keep", "line 5 Foox not tag 1234-12.3 same offset 123 keep", "line 6 has no Foo number: keep", "line 7 Foo yyyy xxx 1234-12.3 this line keep", "line 8 Foo xxxx zzzz 1234-12.4 different n keep", "TOSS 9 Foo kill this 1234-12.3 one DELETE", "line 10 no Foo number: keep", ] [ "line 1 this line has no Foo number: keep", "line 2 Foo something 1234-12.3 other 123 first valid keep", "line 4 Foo not same 1234-12.3 offset 123 line keep", "line 5 Foox not tag 1234-12.3 same offset 123 keep", "line 6 has no Foo number: keep", "line 7 Foo yyyy xxx 1234-12.3 this line keep", "line 8 Foo xxxx zzzz 1234-12.4 different n keep", "line 10 no Foo number: keep", ]
Give a man a fish: <%-{-{-{-<
In reply to Re: Array Exact Position Filter
by AnomalousMonk
in thread Array Exact Position Filter
by Perolizador
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |