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

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.

Replies are listed 'Best First'.
Re^4: .. operator and not including the condition of right operand
by tlm (Prior) on Apr 28, 2005 at 12:18 UTC

    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