I have a HoH structure—actually a mix of hashes and arrays. It's created by reading an XML file, using XML::Simple. If I bless the interior hashes, am I going to mess up:
If I bless the interior hashes that represent InspectionData, FileRecord and Inspector into their own classes, would/should that give indigestion to the XMLout routine? Would it represent a sin against Object Oriented design or otherwise be a venial sin?HASH(0xb82b64) 'InspectionRecord' => ARRAY(0xc207f0) 0 HASH(0xb82be8) 'FileRecord' => ARRAY(0xc20790) 0 HASH(0xb82d08) 'filename' => 'yelloJello.pl' 'Inspector' => ARRAY(0xc3cfc8) 0 HASH(0xb82c84) 'user' => 'smith_j' 'date' => '12-AUG-2007' 'fdnum' => 'D0000'
XML::Simple stores attributes as hash references and child entities as array references (if you've used the recommended 'ForceArray' option, which I have.) There are a couple places in my code where I walk the key/value pairs of each HoH, testing to see if the value is an arrayref or a hashref:
If I understand rightly, once I've blessed the InspectionRecord etc. $type isn't going to get set to HASH anymore - it's going to come back as InspectionRecord. The code that does this test isn't specific to the Inspection project; it's supposed to be general to anything read in by XML::Simple. So I'm reluctant to added tests there to see if $type is a InspectionRecord, FileRecord, Inspector...my $type = ref $hohref; if(not $type){ ....} elsif($type eq 'ARRAY'){ ....} elsif($type eq 'HASH'){ ....} else{ ....}
Am I going about this the right way?
In summary, Randall Schwartz said
The bless operation puts a little post-it note on the hash data structure (not the reference!) that says ``I belong to Widget''.How do I keep from choking on the post-it note?
throop
In reply to Blessing interior hashes by throop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |