Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: What operator should perl5porters use for safe dereferencing?

by dsheroh (Prior)
on May 30, 2012 at 10:36 UTC ( #973250=note: print w/replies, xml ) Need Help??

in reply to What operator should perl5porters use for safe dereferencing?

First gut reaction was ~> but, on further reflection, I decided that it's a bad match (no pun intended) for the normal meaning/behavior of ~ in Perl. =~ is a regex match and ~~ is a smart(ish) match, but this "safe dereference" isn't doing any kind of matching at all.

So I ended up voting for ->> because it's the same as the normal dereferencing operator, modulo a key bounce, making it quick to type. I think --> would have been more aesthetically pleasing than ->>, plus the added character is non-shifted which makes it a little more convenient to add/remove while debugging/testing, but it wasn't on the list of options.

My real preference, though, would be for -> to do a safe dereference by default, optionally with a warning. (Personally, I'd prefer any warning to only be enabled if explicitly requested, not just by a blanket use warnings or perl -w, but I recognize that this would be inconsistent with current warnings.) Given how often I find myself writing things like if ($foo->bar && $foo->bar->baz) {...}, I have to disagree with the earlier comment saying that if any link in that chain is undef, then you obviously have a problem - it's entirely possible that $foo may simply not have a bar and that's that.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2019-06-20 03:28 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (89 votes). Check out past polls.