Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: What operator should perl5porters use for safe dereferencing? by dsheroh
in thread What operator should perl5porters use for safe dereferencing? by de-merphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-18 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found