Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: References quick reference

by lachoy (Parson)
on Apr 05, 2001 at 03:46 UTC ( #69946=note: print w/replies, xml ) Need Help??


in reply to References quick reference

Great summary. Personally, I find the following:

@{$aRefs[0]} @{$aRefs{key}} @{getArrayRef()} %{$hRefs[0]} %{$hRefs{key}} %{getHashRef()}

much cleaner and easier to read than:

@array @$aRef %hash %$hRef $array[0] $$aref[0] $hash{KEY} $$href{KEY}

Maybe it's just me, but I've been using perl for 4+ years and I have never liked stringing the variable characters one after the other (%$). Particularly epxressions like the third and fourth line in the second group above.

I've always thought that using the @{ } %{ } syntax more clearly and consistently evoked what I'm trying to say -- you can use it with variables, method calls/subroutines, etc. I'm interested if other folks feel differently -- it seems to be a matter of taste rather than an opportunity to define yet another One True Way :-)

Chris
M-x auto-bs-mode

Replies are listed 'Best First'.
(tye)Re2: References quick reference
by tye (Sage) on Apr 05, 2001 at 21:44 UTC

    I definitely avoid $$hRef{key} and $$aRef[0] (using $hRef->{key} instead). But I don't really like @{...} much (too hard to match up the open and close braces) so I prefer @$aRef and %$hRef to the versions with {}. For @{$aRefs{key}} I have no choice.

    But when (and if) a version of Perl comes out with "the patch" applied, I'll be switching to nearly exclusively using -> to deference. This patch allows $aRef->@, $hRef->%, $aRef->@[1..5], etc. which are particularly nice for cases like $aRefs->{key}->[0]->getList()->@[2..6].

            - tye (but my friends call me "Tye")
Re^2: References quick reference
by gobisankar (Acolyte) on Apr 30, 2010 at 07:03 UTC
    Very good...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://69946]
help
Chatterbox?
[MidLifeXis]: Project Admin, a while ago: "No, I would prefer you didn't close that ticket yet confirming $vendor's support process yet. Continue to periodically check back to see if it has changed."...
[MidLifeXis]: Project Admin, today, after many periodic updates from me: "Why hasn't this been closed yet? Is there anything I can do to get this closed?" <facepalm>
[MidLifeXis]: In addition to SOAP (last hour of cb), try water. ;-)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2017-01-19 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.