in reply to Strange Behavior while Parsing Sendmail logs

I like this construct better, though an if block is easier to read: s/.* to=([^,]+), .*/$1/ && do { $to_addr = $_ }; If the substitution succeeds, $to_addr is set to the new value of $_.

Replies are listed 'Best First'.
Style Question
by Adam (Vicar) on Jul 19, 2000 at 03:00 UTC
    Out of curiosity, what does phrasing it in that way buy you?

    I thought maybe you were gaining an advantage from the short circuit of && so I wrote a benchmark, but the times came back so close together that the difference is easily attributed to background processes. So I ran the deparser and found that perl converts this to an if(){} structure, which is (as you said) easier to read.

    E:\Projects>perl -MO=Deparse -we "my $s; $_ && do { $s = $_ }" my $s; if ($_) { $s = $_; } -e syntax OK
      My guilty admission is that I just like the way it looks better.