In particular, the syntax for my $workspace (@$decoded) seems really weird to me.

It does not seem weird to me, but for me it is very normal to choose to work with references rather than real arrays. In particular for function calls, it is much more efficient for a function to return a reference than to return a full list (of arbitrary length) to the caller.

It takes some getting used to, the core concept is that when declaring a variable the sigil specifies the type of container, but when accessing a variable the sigil specifies the type of structure we are asking for. Thus:

my @a = (1 .. 5); say $a[0]; # '$' sigil, we are picking out a scalar say @a[3,1,2]; # '@' sigil, we are picking out a list (an array-like + structure) my %h = (a => 1, b => 2, c => 3); say $h{a}; # '$' sigil, we are picking out a scalar say @h{qw{b c}}; # '@' sigil, we are picking out a list say %h{qw{a c}}; # '%' sigil, we are picking out a hash slice (a hash- +like structure)

With references it is similar, except that the reference itself is always a scalar that needs dereferencing

my $aref = [ 1 .. 5 ]; say $aref->[0]; # or ${$aref}[1] say @{$aref}[3,1,2]; my $href = { a => 1, b => 2, c => 3 }; say $href->{a}; # or ${$href}{a} say @{$href}{qw{b c}}; say %{$href}{qw{a c}};

Given this, it is natural that given an array reference $aref we would reference the whole array as @$aref, and given a hash reference $href we would reference the whole hash as %$href.


In reply to Re: Adjusting variable context when workign with JSON data? by hv
in thread Adjusting variable context when workign with JSON data? by unmatched

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.