Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl: last evaluated value as a returned value for a subroutine. See inside

by choroba (Bishop)
on Feb 21, 2013 at 17:05 UTC ( #1019985=note: print w/replies, xml ) Need Help??


in reply to Perl: last evaluated value as a returned value for a subroutine. See inside

If you do not want the last value, return something else:
sub mySub { if ($R) { return; } else { print "CONDITION WORKS\n"; $R = "some string\n"; } }

Usually, your subroutine should return a value and not print anything, or it should print something, but then you should call it in a void context (or a boolean one, checking for success). Making it both print and return a value to be printed makes it harder for reuse.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: Perl: last evaluated value as a returned value for a subroutine. See inside
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019985]
help
Chatterbox?
[GotToBTru]: a few years ago, when we had 3 dogs, the largest of them caught a chipmunk, but did not know what to do with it other than hold it in his mouth
[GotToBTru]: my wife told him to spit it out, so he did
[erix]: yeah, modern dogs are cute tjhat way :)
[erix]: except of course, the RHODESIAN LION HOUND ! :)
[Discipulus]: in roma cars are good mouser.. fortunnately no mouse at 7th floor..
[GotToBTru]: that's a name that should always be accompanied by a trumper fanfare
[GotToBTru]: trumpet, not trumper
[GotToBTru]: good thing too, Discipulus, no roads on the 7th floor either
[GotToBTru]: okay, fess up, who installed CB::Typo?
[Discipulus]: at 7th floor seagulls eat mice

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2017-11-17 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (272 votes). Check out past polls.

    Notices?