... sigh ...

The ultimate reason for that sigil table for P5 is context propagation

Take §{EXPR} = EXPR2 with § as first sigil

I'm always confused how Perl6 is handling that, and I can't remember it long after looking it up.

BUT this is one of the biggest obstacle for backwards compatibility.

The table is also "cheating" in the scalar column, because %$ and @$ denotes de-referencing .

Which is indeed a PITA in Perl5 and IMHO one of the top problems for beginners.

E.g. in order to pass an array to a sub we have to reference

func(\@arr);

but inside the sub we need to start fiddling with array-refs and a new syntax with plenty of arrows

sub func { my $arr =shift; print "First: $arr->[0]"; print "Nested List @{$arr->[0]}"; }

I would rather have preferred a new lexical pragma in Perl5 to automatically alias "$ref-form" with "@list-form of a variable.

I.e. the declaration my @arr automatically implies $arr =\@arr and (somehow) vice versa.

Like this $arr[0] and $arr->[0] would lead to the same result and many arrows could be saved.

This would come with the cost of fusing the namespace for scalars and arrays, but

  1. using the same symbol arr for different vars is considered bad style anyway
  2. it'll stay fully compatible to old code, by simply avoiding the pragma

Perl inherited this dilemma from Perl4 where the list form of @arr was very convenient, but most other dynamic languages I know operate with the ref form (without sigil) by default.

arr=[] is a ref/obj in JS, Python and Ruby

If these languages need the flattened list form of arr they apply a method or a postfix syntax. You could say everything is a scalar there.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^3: Hash Curious (context/dereferencing/backwards compatible) by LanX
in thread Hash Curious by cadphile

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.