Find the answer to your Linux question:
Results 1 to 3 of 3
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 Code: while(<>) { next if(defined($dateStr) && ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2002
    Posts
    2

    Help with this regex in Perl


    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

    Code:
    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

    Thanks

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    949
    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
    Just Joined!
    Join Date
    Nov 2002
    Posts
    2
    Thanks a lot. Solved



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

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

    Code:
    $_ =~ 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
    $spacer_close

Posting Permissions

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