Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Print Vs Return In a Subroutine

by heatblazer (Scribe)
on Mar 30, 2012 at 18:06 UTC ( [id://962662]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Print Vs Return In a Subroutine
in thread Print Vs Return In a Subroutine

No offense here but in that example I don`t see the point in return/print issue the author of the node asked. I am new to Perl, but as far as I got it the return statement of ax() function you defined is returning 1 because of the successful printing, while bx() just returns a variable content. If print is a function then calling it from another function is the same as calling sprintf... which one of them is better, that I don`t know. Since it`s more than 1 way to do it, I think the owner of this node must choose for him/herself.

Replies are listed 'Best First'.
Re^4: Print Vs Return In a Subroutine
by wwe (Friar) on Mar 31, 2012 at 21:49 UTC
    This is exactly the point the question is not clear to me. The question sound a bit like "I'm singing" and "I'm dancing" what's faster? The difference between return value and print out to the screen is less in terms of speed but much more in terms of what are going to do? If you are happy with printing the result of the sub to the screen - go on there is nothing wrong with it and there is also no need to return the result to a caller and print it there. But if you want to collect the results of the calculation and do furher processing maybe an average of multiple runs or save it to the database there is the only way to pass a value back to the caller and printing to a screen is completely useless.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found