in reply to Print only if pattern matches
The script can be re-written so:
#! perl use strict; use warnings; while (my $line = <DATA>) { if ($line =~ / ^ \d+ \| (\d+?) \| /x && $1 == 1 && $line =~ s{ ^ (.*\|)* # $1 .*ABC\.pi= ([\d.]+|[\w.]+)* # $2 .*ABC\.id= (\d+|[\w.]+) # $3 .* $ } {$1$2|$3}sx) { print "$1$2|$3\n"; } } __DATA__ ...
While this “works”, it is dubious: the * quantifier in a regex means match zero or more of the preceeding; in the substitution, do you really want to match zero occurrences of (.*\|) or ([\d.]+|[\w.]+)? If not, use the + quantifier meaning one or more.
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
In Section
Seekers of Perl Wisdom