Bro. Doug has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed Monks,
I understand that undef() and hashes are not meant for each other. That said, I was wondering if anyone could specifically explain the wierdness occurring when you run the following piece of code.
It seems to me that the hash is undefined until you try to assign something to it, and it doesn't matter what that something is. Also, I'm confused as to why, in this case, using undef as a function actually performs the undefine on the hash.
Peace monks,
Update:
I've followed advice and added use warnings and use strict (this started as a perl -e that was being passed around my office). We've also used Data::Dumper on it, just for play.
I understand that undef() and hashes are not meant for each other. That said, I was wondering if anyone could specifically explain the wierdness occurring when you run the following piece of code.
#! /usr/bin/perl use strict ; use warnings ; local $\ = "\n" ; # some formatting my %h ; print ( defined %h ? "Defined!" : "Undefined!" ); undef( %h ) ; print ( defined %h ? "Defined!" : "Undefined!" ); %h = undef ; print ( defined %h ? "Defined!" : "Undefined!" ); undef( %h ) ; print ( defined %h ? "Defined!" : "Undefined!" ); #OUTPUT #Undefined! #Undefined! #Defined! #Undefined!
It seems to me that the hash is undefined until you try to assign something to it, and it doesn't matter what that something is. Also, I'm confused as to why, in this case, using undef as a function actually performs the undefine on the hash.
Peace monks,
Update:
I've followed advice and added use warnings and use strict (this started as a perl -e that was being passed around my office). We've also used Data::Dumper on it, just for play.
Bro. Doug :wq
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: hash assignment wierdness
by DigitalKitty (Parson) on Apr 20, 2007 at 16:00 UTC | |
by shmem (Chancellor) on Apr 21, 2007 at 12:33 UTC | |
Re: hash assignment wierdness
by logie17 (Friar) on Apr 20, 2007 at 15:56 UTC | |
Re: hash assignment wierdness
by Errto (Vicar) on Apr 20, 2007 at 17:59 UTC | |
Re: hash assignment wierdness
by Ploux (Acolyte) on Apr 20, 2007 at 16:00 UTC | |
Re: hash assignment wierdness
by Obidan (Initiate) on Apr 20, 2007 at 18:06 UTC |
Back to
Seekers of Perl Wisdom