Jo Rhett (jorhett) wrote,
Jo Rhett

  • Mood:

Perl is psychic!

Okay, you got to love this. Perl is psychic. It knows that an undefined value is a hash. I'm sorry, would be a hash if an alternate reality had been taken. But it wasn't, so that value is not a hash. It should be NULL. Very odd.

use strict;
my( $hashref );
if( something which isn't true ) {
   $hashref = &getMeABabyBackHash();
print "hashref is a " . ref( $hashref ) . ".\n";

hashref is a HASH.

Really? How odd, given that hashref was never defined.

It is unfortunately not simple enough to provide a 6-line script which demonstrates this. It has something to do with the routine being inside a package, or the fact that the conditional isn't known until a file is read in and evaluated. I'm trying to figure out what the limitation is. But it's very odd, given that the code expects the undefined hash to have an address of 0.
Tags: tech

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded