in reply to .. operator and not including the condition of right operand

foreach (@aap) { if( /^1/ ... !/^0/ ){ print "$_\n" } } __END__ 1mies 2mies 1mies 6mies


Replies are listed 'Best First'.
Re^2: .. operator and not including the condition of right operand
by Roy Johnson (Monsignor) on Apr 27, 2005 at 20:00 UTC
    Try that with
    my @aap = qw(1one two three four 0stop done);
    The difference between the two-dot and three-dot forms is merely that the RHS will not be evaluated on the same pass as the LHS for the three-dot form. Your expression guarantees that a line beginning with 1 and any following lines beginning with 0 will be printed, plus one line that doesn't begin with 0.

    Caution: Contents may have been coded under pressure.
      ... if( /^1/ ... /^(0.*)/ ) { $1 and next; print "$_\n"; } ...


        That will work except when $1 is 0 (which it can be). The three-dot form isn't making a difference in results here, although I suppose it saves some pattern matching. I'd do
        if((/^1/ ... /^0/) =~ /^\d+$/ ){
        although in this case
        if(/^1/ ... (/^0/ && next)){
        works rather neatly.

        Caution: Contents may have been coded under pressure.
Re^2: .. operator and not including the condition of right operand
by tlm (Prior) on Apr 27, 2005 at 20:00 UTC

    This fails with a different input:

    % cat aap2 0aap 0noot 1mies 2mies 3mies 0aap 0noot 1mies 6mies % perl -nle 'print if (/^1/...!/^0/)' aap2 1mies 2mies 1mies 6mies
    Correct output should include 3mies.

    the lowliest monk