I, too, am a bit confused about just what you want. See much more about working with complex data structures in the Perl Data Structures Cookbook.

However, here's an approach that might be useful:

Win8 Strawberry 5.8.9.5 (32) Sun 09/24/2023 19:20:01 C:\@Work\Perl\monks >perl use strict; use warnings; # Subscription DATA sets my @Subscription = ( { 'Sub_Name' => "Morph", 'Archive_File' => "Morph Archive.txt", } +, { 'Sub_Name' => "Cat", 'Archive_File' => "Cat Archive.txt", } +, { 'Sub_Name' => "Hydro", 'Archive_File' => "Hydro Archive.txt", } +, { 'Sub_Name' => "Foo", 'Zip' => "Xyzzy Archive.txt", } +, { 'Sub_Name' => "Bar", } +, { 'Xyzzy' => "Foo", 'Archive_File' => "Xyzzy Archive.txt", } +, { 'Xyzzy' => "Foo", 'Zot' => "Xyzzy Archive.txt", } +, { 'Xyzzy' => "Bar", } +, ); key_extract_and_handle(\@Subscription, 'Sub_Name', \&hashref_handler_e +xample); exit; sub key_extract_and_handle { my ($ar_hashes, # required: ref to array of refs to hashes (A +oH) $key_to_handle, # required: string: key in each hash to handl +e $cr_handle, # required: ref to code of handler ) = @_; for my $hash_ref (@$ar_hashes) { $cr_handle->($hash_ref, $key_to_handle); } } sub hashref_handler_example { my ($hashref, # required: ref to hash $key_to_handle, # required: string: key in hash to handle ) = @_; print "checking subscription "; if (exists $hashref->{$key_to_handle}) { print "'$hashref->{$key_to_handle}' "; } else { print "(exception: subscription key '$key_to_handle' absent) \ +n"; return; # or maybe warn or die } print "via archive file "; if (exists $hashref->{'Archive_File'}) { print "'$hashref->{'Archive_File'}': "; } else { print "(exception: archive file absent) \n"; return; } # do actual subscription currency check here print "ok \n"; # or whatever... } ^Z checking subscription 'Morph' via archive file 'Morph Archive.txt': ok checking subscription 'Cat' via archive file 'Cat Archive.txt': ok checking subscription 'Hydro' via archive file 'Hydro Archive.txt': ok checking subscription 'Foo' via archive file (exception: archive file +absent) checking subscription 'Bar' via archive file (exception: archive file +absent) checking subscription (exception: subscription key 'Sub_Name' absent) checking subscription (exception: subscription key 'Sub_Name' absent) checking subscription (exception: subscription key 'Sub_Name' absent)

Update: Posting error at about line 18
    key_extract_and_handle(\@Subscription, 'Sub_Name', \&hashref_handler_example);
Semicolon was missing at end of statement. Fixed.


Give a man a fish:  <%-{-{-{-<


In reply to Re: How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine (updated) by AnomalousMonk
in thread How can I send a "transposed slice" of an array of hashes and by extension an array of arrays, or hash of hashes to a subroutine by ObiPanda

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.