I left the function but otherwise gutted all the code. I can gut the function a lot more but am concerned the I might not be able to implement the answer so I left it in

#!/usr/bin/perl -w # use strict; ######################################## my %h00 = ( "--link" => "/etc/httpd/SSL", "--fold" => "/ +usr/local/private/QA/apache/SSL", ); my %h01 = ( "--link" => "/etc/httpd/conf/httpd.conf", "--file" => "/ +usr/local/private/QA/apache/conf/httpd.conf", ); my %h02 = ( "--link" => "/etc/httpd/conf.d/httpd.conf", "--file" => "/ +usr/local/private/QA/apache/conf.d/nagios.conf", ); my @a00 = ( \%h00, \%h01, \%h02, ); my %H00 = ( "--system", 'Apache', "--slinks", \@a00,); my @LINKS = ( \%H00,); my @LITERALS = ( '--system' => 'Apache', '--slinks' => \( { "--link" => "/etc/httpd/SSL", "-- +fold" => "/usr/local/private/QA/apache/SSL", }, { "--link" => "/etc/httpd/conf/httpd.conf", "-- +file" => "/usr/local/private/QA/apache/conf/httpd.conf", }, { "--link" => "/etc/httpd/conf.d/httpd.conf", "-- +file" => "/usr/local/private/QA/apache/conf.d/nagios.conf", }, ), ); print "LINKS ==============================\n"; &LinksLS(\@LINKS); print "LITERALS ==============================\n"; &LinksLS(\@LITERALS); ######################################## sub LinksLS() { my $aref = shift; my $aref_ndx; # index into "master" links array my $hash_ref; my $inner_hash_ref; my $sskey; my $system; my $slinks; my $nlinks; my $s; my $file; my $fold; my $link; for $aref_ndx (0..$#{$aref} ) { print '$$aref[ ' . $aref_ndx . '] = ' . $$aref[$aref_ndx] . "\n"; $hash_ref = $$aref[$aref_ndx]; $system = $hash_ref->{"--system"}; $slinks = $hash_ref->{"--slinks"}; $nlinks = @{$slinks}; $s = ($nlinks == 1) ? "" : "s"; print 'System ' . $system . " requires " . $nlinks . " link$s\ +n"; foreach $sskey ( keys %$hash_ref ) { print "\t\t" . $sskey . " is " . + $hash_ref->{$sskey} . "\n"; } undef $file; undef $fold; undef $link; foreach $inner_hash_ref ( @{$slinks} ) { print "\t" . $inner_hash_ref . "\n"; $link = $inner_hash_ref->{"--link"}; $file = $inner_hash_ref->{"--file"}; $fold = $inner_hash_ref->{"--fold"}; if ( not defined $link ) { die "$system --link is undfined, aborting!\n"; } elsif ( not defined $file and not defined $fold ) { die "$system both --file and --fold are undfined, abor +ting!\n"; } elsif ( not defined $file ) { print "\tFOLDER LINK: $link/ -> $fold/\n"; } elsif ( not defined $fold ) { print "\tFILE LINK: $link -> $file\n"; } } } }

In reply to Re^2: How to initialize an array of hash references to hashes using literals by jpietras
in thread How to initialize an array of hash references to hashes using literals by jpietras

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.