Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

RE: I use return on a subroutine

by anders (Initiate)
on May 26, 2000 at 22:16 UTC ( #15059=note: print w/replies, xml ) Need Help??

in reply to I use return on a subroutine

Since perl allways returns the value of the last expression, I usually just states $something if the sub's supposed to return some object.

For subs that prints stuff, I leave it to print() to decide.

If an error occurs, I use return 0 after setting an error value if possible.

Replies are listed 'Best First'.
RE: RE: I use return on a subroutine
by BBQ (Deacon) on May 27, 2000 at 06:43 UTC
    Interesting... I do it the other way around!
    my $txt2print = MySub('This text') or warn('MySub said 0'); print $txt2print; sub MySub { my $txt = shift; $txt = { do something here } or return(0); return($txt); }
    or is that what you where saying all along?
      Sometimes I do this too. I guess it's just a matter of preference. Does anyone have a reason to use one or the other?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://15059]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-02-23 12:58 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.