Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:27:27+00:00 2026-06-09T04:27:27+00:00

I’m stuck yet again and need some assistance. As usual, it’s my nemesis –

  • 0

I’m stuck yet again and need some assistance. As usual, it’s my nemesis – Hashes.
Essentially, I’m trying to write to a database, all the items of software on a z/OS mainframe. I have managed to progress to the following hash:

$VAR1 = {
    'Product' => {
        'Unicenter CA-Deliver Output Management' => {
            'vendorUniqueKeyRef' => 'CA',
            'swUniqueKey'        => 'RMO',
            'description'        => 'Unicenter CA-Deliver Output Management'
        },
        'Unicenter CA-JCLCheck Utility' => {
            'vendorUniqueKeyRef' => 'CA',
            'swUniqueKey'        => 'JCLCHECK',
            'description'        => 'Unicenter CA-JCLCheck Utility'
        },
        'EREP Environmental Recording Edit Print' => {
            'vendorUniqueKeyRef' => 'IBM',
            'swUniqueKey'        => 'EREP',
            'ProductVersion'     => {
                'version'       => '3',
                'swUniqueKey'   => '5658-260',
                'name'          => 'EREP Environmental Recording Edit Print',
                'versionNumber' => '03'
            },
            'description' => 'EREP Environmental Recording Edit Print'
        },
        'SYSQL' => {
            'vendorUniqueKeyRef' => 'SPLWDGRP',
            'swUniqueKey'        => 'SYSQL',
            'ProductVersion'     => {
                'ProductVersionRelease' => {
                    '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' => {
            'vendorUniqueKeyRef' => 'IBM',
            'swUniqueKey'        => '3270PCFT',
            'description'        => '3270-PC File Transfer Program'
        },
        'Tivoli OMEGAMON XE on z/OS' => {
            'vendorUniqueKeyRef' => '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' => {
            'vendorUniqueKeyRef' => 'IBM',
            'swUniqueKey'        => 'DB2UTSU',
            'ProductVersion'     => {
                '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'}{'ProductVersionRelease'}
                {'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.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:27:28+00:00Added an answer on June 9, 2026 at 4:27 am

    I think you are using XML::Simple? If so you would be far better off using an XML parser that gives you XPath-like access to your data, such as XML::LibXML or XML::Twig.

    As it stands you would be better off maintaining scalar variables to point at each step inside the hash structure. That would avoid multiple keys to access an element as well as using the same hash access repeatedly. You shouldn’t copy to another hash as you do in my %sw = %{ $sw->{'Product'} } because there is no point in copying all the hash keys and values. I have used my $products = $sw->{Product} in the code below, and then my $product = $products->{$prodname} and my $pv = $product->{ProductVersion}.

    You would also benefit by using hash slices, and the code sould be clearer if you dropped the quotes from around the hash keys (this works only if the keys are alphanumeric). I pull out the first three product parameters in one line using a slice.

    Here is a rewrite of the piece of code you showed us. The biggest change is that I have checked to see whether there is a ProductVersion/version element. If so then I combine version and ProductVersionRelease/release from beneath ProductVersion. Otherwise I do the same beneath all ProductVersion/* elements. The // defined-or is useful to default these values to zero if they are not present.

    I hope this is closer to what you wanted.

    my $products = $sw->{Product};
    
    foreach my $prodname (keys %$products) {
    
        print "\n\nNow processing $prodname\n";
    
        my $product = $products->{$prodname};
    
        my ($description, $vendorUniqueKeyRef, $swUniqueKey) =
                @$product{qw/ description vendorUniqueKeyRef swUniqueKey /};
    
        my @versions;
        if (my $pv = $product->{ProductVersion}) {
            for my $ver (exists $pv->{version} ? $pv : values %$pv) {
              push @versions, sprintf "%d.%d",
                  $ver->{version} // 0,
                  $ver->{ProductVersionRelease}{release} // 0;
            }
        } 
    
        print "***************\n";
        print "The product is: $prodname\n";
        print "The description is: $description\n";
        print "The vendorUniqueKeyRef is: $vendorUniqueKeyRef\n";
        print "The ProductVersion is: $_\n" for @versions;
        print "The swUniqueKey is: $swUniqueKey\n";
        print "***************\n";
    }
    

    output

    Now processing DB2 Utilities Suite for z/OS
    ***************
    The product is: DB2 Utilities Suite for z/OS
    The description is: DB2 Utilities Suite for z/OS
    The vendorUniqueKeyRef is: IBM
    The ProductVersion is: 9.0
    The ProductVersion is: 7.0
    The swUniqueKey is: DB2UTSU
    ***************
    
    Now processing UMB
    ***************
    The product is: UMB
    The description is: UMB
    The vendorUniqueKeyRef is: CSC
    The swUniqueKey is: CSCUMB
    ***************
    
    Now processing EREP Environmental Recording Edit Print
    ***************
    The product is: EREP Environmental Recording Edit Print
    The description is: EREP Environmental Recording Edit Print
    The vendorUniqueKeyRef is: IBM
    The ProductVersion is: 3.0
    The swUniqueKey is: EREP
    ***************
    
    Now processing Unicenter CA-JCLCheck Utility
    ***************
    The product is: Unicenter CA-JCLCheck Utility
    The description is: Unicenter CA-JCLCheck Utility
    The vendorUniqueKeyRef is: CA
    The swUniqueKey is: JCLCHECK
    ***************
    
    Now processing Unicenter CA-Deliver Output Management
    ***************
    The product is: Unicenter CA-Deliver Output Management
    The description is: Unicenter CA-Deliver Output Management
    The vendorUniqueKeyRef is: CA
    The swUniqueKey is: RMO
    ***************
    
    Now processing 3270-PC File Transfer Program
    ***************
    The product is: 3270-PC File Transfer Program
    The description is: 3270-PC File Transfer Program
    The vendorUniqueKeyRef is: IBM
    The swUniqueKey is: 3270PCFT
    ***************
    
    Now processing SYSQL
    ***************
    The product is: SYSQL
    The description is: SYSQL
    The vendorUniqueKeyRef is: SPLWDGRP
    The ProductVersion is: 2.1
    The swUniqueKey is: SYSQL
    ***************
    
    Now processing Tivoli OMEGAMON XE for Messaging for z/OS
    ***************
    The product is: Tivoli OMEGAMON XE for Messaging for z/OS
    The description is: Tivoli OMEGAMON XE for Messaging for z/OS
    The vendorUniqueKeyRef is: IBM
    The swUniqueKey is: OMXEMES
    ***************
    
    Now processing Tivoli OMEGAMON XE on z/OS
    ***************
    The product is: Tivoli OMEGAMON XE on z/OS
    The description is: Tivoli OMEGAMON XE on z/OS
    The vendorUniqueKeyRef is: IBM
    The ProductVersion is: 3.0
    The swUniqueKey is: OMXEZO
    ***************
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.