I'm looking for help understanding dereferencing with a complex data structure. I have an array of references to anonymous arrays which in turn contain a scalar as a the first item and a reference to an anonymous hash as the second item:

push @lecshun, [$barename , {package=>$gem, index=>$dexi}];

For some items in the array I want to add another key-value pair to the hash, but I just cannot figure out how to do that. I have only gotten so far:

$lecshun[$dexi - 1] ##? <<-- what to do here ?## = inv($gem);

The subroutine inv is this, although it could be anything:

sub inv { my $pkg = $_[0]; my @pki = qx{cygcheck -i --inst $pkg}; for my $ln (@pki) { next unless $ln=~/^Version\s+:\s(\S+)/; say "Pkg ".$1; return (datum => $1); } }

Maybe I am making this too complicated for myself.

Jan 16, 2025 at 02:07 UTC

A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen -> I.G.Y.
(Slightly modified for inclusiveness)


In reply to Adding a new key-value pair to a nested anonymous hash by Intrepid

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.