Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Dereferencing in blessed object

by LanX (Saint)
on Feb 26, 2021 at 12:52 UTC ( [id://11128829]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Dereferencing in blessed object
in thread Dereferencing in blessed object

> If you start getting into deeper structures then the increasing levels of syntax needed to deal with the $$foo{bar} equivalents is going to get messy.

Could you give an example? I hope you are not referring to redundant -> arrows at deeper levels.

> But I do not quote hash keys

Neither do I, I just copy pasted from B::Deparse's output.

edit

> I don't see objectively why it would be,

Like Bliako said, I have trouble parsing precedence, and I don't think it's only a matter training.

can you immediately tell if $$x{key} means ${$x}{key} or ${$x{key}} ?

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

Replies are listed 'Best First'.
Re^5: Dereferencing in blessed object
by hippo (Bishop) on Feb 26, 2021 at 14:56 UTC
    Could you give an example? I hope you are not referring to redundant -> arrows at deeper levels.

    Quite the opposite, actually. By "equivalents" I was meaning the same syntax but for different data. eg. if we have $foo = { bar => [4, 5, 6] } and we want to operate on the array we can use @{$foo->{bar}} which is fine or @{$$foo{bar}} which, while valid, is a bit syntax heavy for my taste. (I like sigils but anything which starts off @{$$ is just asking to be clarified)

    can you immediately tell if $$x{key} means ${$x}{key} or ${$x{key}} ?

    I can but that's (a) from experience and (b) because sigils bind most tightly (as you said: precedence). It would not be a surprise to find that someone new to Perl would struggle with this too.

    Don't get me wrong - I agree with the presumed majority who use the arrow most/all of the time. However I do recognise it is a subjective choice and don't criticise others for avoiding it.


    🦛

      > @{$foo->{bar}} which is fine

      personally I'd prefer having autoboxing methods

      $foo->{bar}->list() (and $foo->{bar}->push() etc ...) cause it reads from left to right

      > or @{$$foo{bar}} which, while valid, is a bit syntax heavy

      And eye and logic have to hop back and forth

      Tangential:

      my dream would be able to have a pragma dualmy which is automatically aliasing each %IDENT with it's ref $IDENT and vice versa.

      Perl would become easier to read and to understand.

      (no implementation details, it's a dream... ;-)

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

Re^5: Dereferencing in blessed object
by haukex (Archbishop) on Feb 26, 2021 at 13:22 UTC
    can you immediately tell if $$x{key} means ${$x}{key} or ${$x{key}} ?

    Personally I've just memorized this special case and yes, when I see $$x{key} or $$y[2] I just know this means $x->{key} or $y->[2]. I sometimes find it a bit nicer because of the parallels bewteen e.g. my %x = ( key => 42 ); print $x{key}; and my $x = { key => 42 }; print $$x{key}, but I also completely understand that people prefer $x->{key}, and I often use this style myself, for example I prefer $self->{key} over $$self{key}.

      I agree that the parallels are nicer. And I don't know if I could get used to it when I tried harder. (as I said PBP had it's influence on me)

      In any case I use @$href{a..c} for slicing references

      DB<42> @h{a..z}=1..26 DB<43> $hr=\%h DB<44> p @$hr{a..c} 123 DB<45>

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found