in reply to binary ids

You could do something like the following:
if ( hex($parent_hex) != 0) { # $parent_hex isn't 0 }
hex will convert a hex string into it's numerical value. Then compare that with 0.

Replies are listed 'Best First'.
Re: Re: binary ids
by tachyon (Chancellor) on Feb 10, 2003 at 18:07 UTC

    In fact all you need is if( $parent_hex == 0 ) { blah } as the numeric comparison forces perl to convert the sv to a number and 0x00000 is correctly interpretted as 0 automagically. The problem with the if (! $parent_hex) {} example given is that without forcing numeric context perl sees the sting '0x0' which is not a null string '' and thus not false in this context.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      This is misleadingly incorrect. You assume that just because the perl compiler will read a plain 0x0005 as the numeric value 5 that the same thing in a scalar behaves the same way. In this case strings with leading numbers are evaluated in numeric context as the value of the leading number. In this case this means that $var = "0x0005"; $var == 5 is false - in fact, $var == 0 because $var begins with the string "0".

      The correct answer is to use the hex() function. You'd have to resort to using eval to get your idea to work (which re-invokes the compiler which has its own rules...).


      Seeking Green geeks in Minnesota

        And you are of course both accurate and correct....

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print