in reply to Re: binary ids
in thread binary ids

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

Replies are listed 'Best First'.
Re^3: binary ids
by diotalevi (Canon) on Feb 10, 2003 at 21:08 UTC

    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