Reputation: 1
Can someone explain me how to understand this part of the code The code is extracted from pfLogSumm.pl a log analyzer for postfix mail
while(<>) {
next if(defined($dateStr) && ! /^$dateStr/o);
s/: \[ID \d+ [^\]]+\] /: /o; # lose "[ID nnnnnn some.thing]" stuff
my $logRmdr;
more code
}
I can't understand what the regex is doing because don't have a assignment, don't have a conditional, simple is there
Upvotes: 0
Views: 95
Reputation: 780889
By default, regular expressions (and many other functions) operate on $_
. So
s/: \[ID \d+ [^\]]+\] /: /o;
is equivalent to:
$_ =~ s/: \[ID \d+ [^\]]+\] /: /o;
This replaces : [ID number ...]
with just :
in the input line.
This is a common idiom that you should see in many Perl scripts, you should be used to it.
Upvotes: 1