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

In the "perverse" category:

use strict; use warnings; my @aap = qw( 0aap 0noot 1mies 2mies 0aap 0noot 1mies 6mies ); for (@aap) { print "$_\n" if - reverse '0' . (/^1(.*)/ .. /^0(.*)/); } __END__ 1mies 2mies 1mies 6mies
I wonder what's more common, the situation described by the OP or the need to know the sequence number of the match? If the former is more common, then I think one could make the case for having the match of the right operand return a string of the form '0En' instead of the current 'nE0'. Then, all that would be required to satisfy the OP's request would be to prepend 0+, or better yet, a minus sign, in front of the .. expression:
if ( -(/^1(.*)/../^0(.*)/) )
whereas if one wanted to keep the line matching the right operand one would omit the 0+ or minus sign:
if ( (/^1(.*)/../^0(.*)/) )
Those who actually wanted the match number, would have to scrape it off the return value:
if ( ( /^1(.*)/../^0(.*)/ ) =~ /(\d+)$/ ) { # $1 contains the sequence number of match
I've tested this scheme a bit, and it seems to work; please let me know if I missed some corner (or not-so-corner) cases.

the lowliest monk

Replies are listed 'Best First'.
Re^3: .. operator and not including the condition of right operand
by bart (Canon) on Apr 28, 2005 at 06:23 UTC
    The reason for appending "E0" is that the value in numerical context is unchanged: "3E0" as an integer is 3 (just like "3E1" is 30; not because numification ignores everything from the "E" till the end). Your value would means zero.

    And I don't think 0+$count is easier than $count =~ /E/. Nor faster, or much faster at least. Your /(\d+)$/ definitely isn't easy, nor likely very fast.

    As you can guess from the generally unknown behaviour of what .. actually returns, neither requirements are very common. That's why I'm most happy with the status, like it is.

      I realize that 0E3 means 0 in numeric context; that's precisely the point. In fact it is "a true zero", because in string context it evaluates to true. The nice thing about this is that simply by prepending a minus sign (or 0+, or 0!=) to the expression one selectively alters the truth value only of the value returned by .. when its right operand is matched; the truth of all the other values returned by this operator remains unchanged. Therefore, with a tiny change one can choose between keeping or discarding the line corresponding to a right-operand match.

      BTW, to use /E/ for the original problem, you'd need two tests and an assignment:

      if ( my $count = /^1(.*)/../^0(.*)/ and $count !~ /E/ )
      which is significantly longer and more involved than
      if ( -( /^1(.*)/../^0(.*)/ ) )
      To use a regex to solve this problem one would need /^\d+$/:
      if ( ( /^1(.*)/../^0(.*)/ ) =~ /^\d+$/ )
      (This is basically one of the solutions that Roy Johnson proposed.)

      the lowliest monk