"I'm trying to understand how this can be rewritten in more simplistic syntax for better understanding."

In my opinion, some of your biggest barriers, with respect to making this more understandable, are the poor choice of variable names:

Beyond the naming issues, if you're encountering (associativity) difficulties with:

X = Y = Z

Then don't do it! This works the same and is abundantly clearer:

Y = Z X = Y

Consider these two versions of your code. As you've provided no context or other indication of the data involved, I've had to contrive names: I'm sure you can do better.

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; { # Contrived, arbitrary values for your variables my %hash1; my %hash2 = (b => [ 1, 2, 3 ]); my ($a, $b) = qw{a b}; # Your code my $sub = $hash1{$a} = $hash2{$b}; push @$sub, $a; # Your data print Dumper $sub; } { # Possibly more meaningful variable names (with same values) my %some_HoA; my %other_HoA = (b => [ 1, 2, 3 ]); my ($key_a, $key_b) = qw{a b}; # Possibly more understandable code $some_HoA{$key_a} = $other_HoA{$key_b}; my $some_array_ref = $some_HoA{$key_a}; push @$some_array_ref, $key_a; # More obvious data? print Dumper $some_array_ref; }

As you can see from the output, the functionality is the same in both pieces of code:

$VAR1 = [ 1, 2, 3, 'a' ]; $VAR1 = [ 1, 2, 3, 'a' ];

There are occasions (e.g. for reasons of efficiency) where hard-to-read, minimalist code is needed. These situations are not the norm; when they do arise, feel free to add copious comments to explain each and every nuance that you think may not be fully understood. Do bear in mind that code you write today may appear crystal clear; when you revisit it at some time in the (not necessarily distant) future, it may be less obvious than it once was.

-- Ken


In reply to Re: Hash to Array assignment? by kcott
in thread Hash to Array assignment? by Anonymous Monk

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.