The "subtle difference" is that push-ing to an array reference was an experimental feature (added circa-5.10 IIRC | added with Perl 5.14, removed as of Perl 5.24) that is now removed. For this reason, I would avoid it even if your particular version of Perl still supports it. (Update: If you intend ever to publish your module, I would absolutely avoid it!)

Win8 Strawberry 5.30.3.1 (64) Sun 04/11/2021 19:15:44 C:\@Work\Perl\monks >perl use strict; use warnings; use Data::Dump qw(dd); my %attrs = qw(foo 1 bar 2);; my @products = ({ 'id' => 0, 'name' => 'Test', 'description' => 'Some test data', 'qty' => 1, 'price' => 1000, }); $attrs{'trolley'} = \@products; my $self = \%attrs; my $new_product = { qw(id 1 name Widget) }; push $self->{'trolley'}, $new_product; # push @{ $self->{'trolley'} }, $new_product; dd \%attrs; ^Z Experimental push on scalar is now forbidden at - line 22, near "$new_ +product;" Execution of - aborted due to compilation errors.


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


In reply to Re: Pushing hash ref onto array ref by AnomalousMonk
in thread Pushing hash ref onto array ref by Bod

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.