Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

As another noted, the worst case isn't when you have something simple like $foo. Plus, I didn't mention the other postfix dereference operators flavors:

$obj->Method()->{key}->@[3,7]; $obj->Method()->{lock}->@{"open","close"};
instead of
@{$obj->Method()->{key}}[3,7]; %{$obj->Method()->{lock}}{"open","close"};

I particularly hate the wide separation of the @ and the [3,7] above.

But you don't have to use it. I agree that taking a reference should be prefix and never proposed (nor saw a proposal for $foo->\. But most of the dereferencing I do is already postfix via -> anyway.

If you don't like it, you must be typing:

${${$obj->Method()}{key}}[0];
instead of either of:
$obj->Method()->{key}->[0]; $obj->Method(){key}[0];
The added postfix dereference operators just round things out so I can use postfix for more than just getting a single element. Note the nice similarity:
$obj->Method()->{key}->[1]; # One element. $obj->Method()->{key}->@[1,2]; # Two elements.
I really doubt I'd write $foo->@, reserving its use for chains of dereferences like above.

Now, the really whacky thing I'd love to see is the list dereference operator, but that patch is just too much work for the size of audience who can appreciate it. It lets you take multi-dimensional slices:

$data->@{qw(this that other)}->>@[3,7]->>Method();
does
my @ret; for( %{$data}{qw(this that other)} ) { for( @{$_}[3,7] ) { push @ret, $_->Method(); } } return @ret;
I had a real use for this when I was automating installations of WindowsNT. To make complex decisions about how to partition and format hard disks, I built a big data structure that described tons of details about the current configuration of your hard disks and partitions. This in itself was very handy but I kept wanting to do things like:
SavePartnSizes( $info->{Disks}->@->>{Partition} ->>@->>@{"Label","SizeMB"} ); #vs. my( @partns, %partnSize ); for my $disk ( @{$info->{Disks}} ) { for my $partn ( @{$disk->{Partition}} ) { push @partns, $partn->{Label}; $partnSize{$partn->{Label}}= $partn->{SizeMB}; } } SavePartnSizes( @partns, @partnSize{@partns} );

It feels a lot like map.

OK, enough rambling.


In reply to RE: RE: Postfix, whole-object dereference operators by tye
in thread keys function question by raflach

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (11)
    As of 2014-10-02 08:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (52 votes), past polls