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

Re: return !!

by Limbic~Region (Chancellor)
on Mar 04, 2009 at 20:29 UTC ( #748311=note: print w/replies, xml ) Need Help??


in reply to return !!

cosmicperl,
I am suprised that no one mentioned why this convention exists. It is likely a candidate for a small "Perl Idioms Explained".

If you are only interested in the truth of an expression, you can save some cycles by not copying the entire data. In this case, I would have preferred return scalar @array because of the way perl handles truth.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: return !!
by ikegami (Patriarch) on Mar 04, 2009 at 20:33 UTC

    you can save some cycles by not copying the entire data.

    Since the context is surely scalar, it wouldn't copy the entire data anyway.

      ikegami,
      I was speaking to the idiom not this specific example. For instance return $foo; where $foo is the contents of a large file. I also am not sure I agree that the author of the sub can be sure that the caller of the sub would be calling it in scalar context - making the explicit scalar useful.

      Cheers - L~R

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-01-21 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?