Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello esteemed Monks,

I'm stuck yet again and need some assistance. As usual, it's my nemesis - Hashes. Why I battle with these as much as I do is really beyond me - it's certainly not a lack of reading FAQ's, PerlDOCs and all manner of other sources of information.
Essentially, I'm trying to write to a database, all the items of software on a z/OS mainframe. Thanks to some help from you all (Help with attributes and XML::Simple) I have managed to progress to the following hash:
$VAR1 = { 'Product' => { 'Unicenter CA-Deliver Output Management' => { 've +ndorUniqueKeyRef' => 'CA', 'sw +UniqueKey' => 'RMO', 'de +scription' => 'Unicenter CA-Deliver Output Management' }, 'Unicenter CA-JCLCheck Utility' => { 'vendorUniqu +eKeyRef' => 'CA', 'swUniqueKey +' => 'JCLCHECK', 'description +' => 'Unicenter CA-JCLCheck Utility' }, 'EREP Environmental Recording Edit Print' => { 'v +endorUniqueKeyRef' => 'IBM', 's +wUniqueKey' => 'EREP', 'P +roductVersion' => { + 'version' => '3', + 'swUniqueKey' => '5658-260', + 'name' => 'EREP Environmental Recording Edit Print' +, + 'versionNumber' => '03' + }, 'd +escription' => 'EREP Environmental Recording Edit Print' }, 'SYSQL' => { 'vendorUniqueKeyRef' => 'SPLWDGRP', 'swUniqueKey' => 'SYSQL', 'ProductVersion' => { 'ProductVersionR +elease' => { + 'releaseNumber' => '01', + 'swUniqueKey' => 'SYSQL-21', + 'name' => 'SYSQL', + 'release' => '1' + }, 'version' => '2' +, 'swUniqueKey' => + 'SYSQL-2', 'name' => 'SYSQL +', 'versionNumber' +=> '02' }, 'description' => 'SYSQL' }, '3270-PC File Transfer Program' => { 'vendorUniqu +eKeyRef' => 'IBM', 'swUniqueKey +' => '3270PCFT', 'description +' => '3270-PC File Transfer Program' }, 'Tivoli OMEGAMON XE on z/OS' => { 'vendorUniqueKe +yRef' => 'IBM', 'swUniqueKey' = +> 'OMXEZO', 'ProductVersion +' => { + 'version' => '3', + 'swUniqueKey' => '5698-A59', + 'name' => 'Tivoli OMEGAMON XE on z/OS', + 'versionNumber' => '03' + }, 'description' = +> 'Tivoli OMEGAMON XE on z/OS' }, 'Tivoli OMEGAMON XE for Messaging for z/OS' => +{ +'vendorUniqueKeyRef' => 'IBM', +'swUniqueKey' => 'OMXEMES', +'description' => 'Tivoli OMEGAMON XE for Messaging for z/OS' }, 'DB2 Utilities Suite for z/OS' => { 'vendorUnique +KeyRef' => 'IBM', 'swUniqueKey' + => 'DB2UTSU', 'ProductVersi +on' => { + 'DB2 Utilities Suite for z/OS' => { + 'swUniqueKey' => '5655-N97', + 'version' => '9', + 'versionNumber' => '09' + }, + 'DB2 Utilities Suite' => { + 'swUniqueKey' => '5697-E98', + 'version' => '7', + 'versionNumber' => '07' + } + }, 'description' + => 'DB2 Utilities Suite for z/OS' }, 'UMB' => { 'vendorUniqueKeyRef' => 'CSC', 'swUniqueKey' => 'CSCUMB', 'description' => 'UMB' } } };

Initially, all was good and I had the following:
my $sw = $xmldoc->{'Catalog'}->{'Products'}; my %sw = %{ $sw->{'Product'}}; foreach my $product (keys %sw) { print "Now processing $product\n"; my $version; my $release; my $description = $sw{$product}{'description'}; my $vendorUniqueKeyRef = $sw{$product}{'vendorUniqueKeyRef'}; my $swUniqueKey = $sw{$product}{'swUniqueKey'}; if ($sw{$product}{'ProductVersion'}) { $version = $sw{$product}{'ProductVersion'}{'version'}; if ($sw{$product}{'ProductVersion'}{'ProductVersionRelease'}) +{ $release = $sw{$product}{'ProductVersion'}{'ProductVersion +Release'}{'release'}; } else { $release = 0; } } else { $version = 0; $release = 0; } my $fullVersion = "$version.$release"; print " ***************\n The product is: $product\n The description is: $description\n The vendorUniqueKeyRef is: $vendorUniqueKeyRef\n The ProductVersion is: $fullVersion\n The swUniqueKey is: $swUniqueKey\n ***************\n"; };

However, I kept getting an error about using uninitialised variables while using strict. I realised that some software had versions like ".2" instead of "2.2" and then saw that I was not properly handling the fact that some products are installed twice with different versions, something which I had stupidly not catered for. I tried to fix that, only to find that not all version versions have a release, which I had tried to cater for, but only if they had been installed once.......
I've read up a load on getting data out of a HoH as well as an AoH, but I can't come right with this.
Essentially I'm trying to get a listing of all the software installed out of this hash into the database using DBD::ODBC (which I already have working for the rest of my program) whether it has a version, multiple versions, versions and releases, multiple versions and no releases, multiple vers...... Well you get the idea.......
I'd appreciate any help that anybody could give as weel as any advice on my current style and error checking.

Regards,
Smaug.
Peddle faster monkeys!! I need more power!!

In reply to Iterative HOH or AOH? by Smaug

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-20 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found