Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: removing duplicates from an array of hashes

by bigj (Monk)
on Apr 18, 2014 at 14:23 UTC ( [id://1082768]=note: print w/replies, xml ) Need Help??


in reply to Re^2: removing duplicates from an array of hashes
in thread removing duplicates from an array of hashes

Reasoning is simple:

I didn't program for a long time (close to 10yrs), I still were sure that $#array is the last item, but I was too lazy to look up, how to note it when it is a $arrayref, so I just took 0..@$arrayref-1 what works same here and for at least where I stopped, it was same idiomatic. Every programmer in the world understand 0..length(array)-1 in a heartbeat, only Perl cracks will understand $[..$#array.

I wasn't aware that I could just $#array -= $n to make the array smaller. To be honest, I'm not sure whether I'd like it. It works only in so rare cases where we basical want to  pop @array, $n and don't care about what were the last items. splice is a clear idiom that we intend to remove entries out of an array and then specify which. If the special case were more often, o.k., but how often do we even use splice? IMHO that is even rare, most of the time we pop, shift or slice with @array[4..7,11..13] and so on, so no need to trick us selfs just to trick us. Code should be easy.

Anyway, pretty to cool to have learned some new tricks in Perl :-)

Greetings,
Janek Schleicher

Log In?
Username:
Password:

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

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

    No recent polls found