Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Help with this regex in Perl

    Can someone explain me how to understand this part of the code
    The code is extracted from 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 undestand what the regex is doing because don't have a assigment, don't have a conditional, simple is there


  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Woodshed, CA
    I don't like Perl, but like any language I would trace through the code to see what its doing. Below is a site that helped the times I've had to do perl it talks about tracing through Perl.

    perl option to trace execution
    A lion does not lose sleep, over the opinion of sheep.

  3. #3
    Thanks a lot. Solved

    By default, regular expressions (and many other functions) operate on $_. So

    s/: \[ID \d+ [^\]]+\] /: /o;
    is equivalent to:

    $_ =~ s/: \[ID \d+ [^\]]+\] /: /o;

    This is a common idiom that you should see in many Perl scripts, you should be used to it.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts