in reply to forcing numeric context

This is why I use !1 as my "false" value. (And I use 0+ to force numeric context.)

        - tye

Replies are listed 'Best First'.
Re: (tye)Re: forcing numeric context
by John M. Dlugosz (Monsignor) on Dec 18, 2002 at 05:35 UTC
    The 0+ works but causes a warning. I went with $v||0 as the simplest in this case. I think I said something like $s=join ',', map { $_||0 } @version;.

      Just to make sure you didn't miss the point. If you use $f= !1 then 0+$f does not cause a warning. So, if you want $f to stay the empty string, you can also use:     $f ||= !1; if you don't have control over how $f is initially set. Then 0+ and sprintf "%d", etc. will all work without giving a warning.

              - tye
        Isn't !1 just an expression that returns 0? No, trying it shows blank. It seems to be a zero-length string. So why is it different from ''? Is it magic?