I have several problems with the "The Need" paragraph already ...

1) you are proposing two "safe" operators in one, the first to avoid magic (autovivification at hash access) the second to introduce magic (ignore error of missing method).

I don't find this consistent.

2) The number of edge cases for the large amount of operators makes Perl hard to memorize, we are not only running out of keyboard characters, but learning Perl becomes increasingly complicated.

3) DWIM shouldn't violate orthogonality, i.e. the ability to understand the syntax logically by composing smaller concepts to a consistent whole.

If P5P wants to extent syntax, than a better support for autoboxing would be the way I'd favour for efficiency and flexibility!

use strict; use warnings; use Data::Dump qw/dd/; my $get = sub { my ($ref ,@path)=@_; for my $member (@path){ return undef unless exists $ref->{$member}; $ref = $ref->{$member}; } return $ref; }; my %hash = ( a=> {b=> {c=> 666} }); dd \%hash; dd $hash{a}->$get(qw/b c/); dd $hash{a}->$get(qw/x x x/); # no autovivification #dd $hash{a}{x}{x}{x}; # autovivification dd \%hash;
->
{ a => { b => { c => 666 } } } 666 undef { a => { b => { c => 666 } } }

Please note that:

a) the name of the method is (or can be) self explanatory ( get is just a guess)

b) this approach is backward compatible, the Perl implementation might be slow but will always work as a fall back

c) performance could be easily improved by XS code in an intermediate step

d) the solution is generic, i.e. any other "missing" operator could be implemented/experimented with and hence orthogonal

e) any new syntax like ~> or whatever could be additionally implemented with a clearly named twin autobox method

Sorry if I didn't read your hole post and didn't supply an example implementation for $call but a flue with fever limits my attention span ATM ;-)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

PS: As a side note, I was first thinking of realizing something like a $safe-method to handle both cases

$name = $user[$idx] -> {'name'}; # may create a hash $name = $user[$idx] -> $safe -> {'name'}; # leaves @user alone $name = $person -> name; # chokes on undef $name = $person -> $safe -> name; # passes undef on

But this would not only imply too much slow magic like a proxy class but also mangle two different concepts in one operator (see point 1)


In reply to Re: RFC: The lightning-rod operator by LanX
in thread RFC: The lightning-rod operator by martin

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.