G'day NewLondonPerl1,
I had some real problems trying to equate your schema (both code and description) with the data you presented. Here's some of the issues:
-
Your generic use of the word "hash", without further qualification, requires assumptions which may not be correct. I'm not trying to be pedantic or obtuse, and I'm pretty sure I've understood your intent throughout, but if I haven't, that may well be the reason.
-
%definition apparently "defines all the keys that a hash should have"; however, this only contains the single key nfs: the hash contains no keys called nfs.
-
%definition:nfs contains a number of keys with various issues:
-
%comment is not a key in the hash.
-
%filer_device's type is not a string; it's a hash.
-
%filer_volume's type is not a path; it's a hash.
-
Overall, there's no indication of the structure where these keys exist.
-
%output:mountnfs: What does the "mountnfs" refer to? It's not mentioned anywhere else.
-
%output:mountnfs:%format seems to have many issues:
-
%tag: What does ths refer to? It's not mentioned anywhere else.
-
%filer_device: The definition suggests a string should be output here but, as mentioned above, the type is wrong.
-
%filer_volume: The definition suggests a path should be output here but, as mentioned above, the type is wrong.
Given all these problems, I am not able to provide a solution that uses your schema. However, the following code generates the output you want. When you've sorted out the schema issues, perhaps you can integrate that into this code. Here's pm_data_1026558.pl:
#!/usr/bin/env perl
use strict;
use warnings;
my $input = do { local $/; <> };
$input =~ y/":/',/;
my $data = eval $input;
for my $file (qw{ny_loc nj_loc}) {
print "$file file =\n";
for my $key (sort grep { ref $data->{$_} eq 'HASH' } keys %$data)
+{
my $home_link_mpt = $data->{$key}{'home_nfs'}{'home-lnk-mpt'};
print join(':', $key,
$home_link_mpt->{'%filer_device'}{$file},
$home_link_mpt->{'%filer_volume'}{$file},
$home_link_mpt->{'%export_name'}
), "\n";
}
print "\n";
}
Here's the output. (The file pm_data_1026558.dat contains the first block of data you posted, verbatim.)
$ pm_data_1026558.pl pm_data_1026558.dat
ny_loc file =
@dev:nydevnfstest10_links:/vol/linkstest10:/links10
@fred:nydevnfs_links:/vol/links:/links
nj_loc file =
@dev:njdevnfstest11_links:/vol/linkstest11:/links10
@fred:njdevnfs_links:/vol/links:/links
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.