Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Better way to write these checks?

by muba (Priest)
on Jun 29, 2012 at 15:52 UTC ( #979141=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Better way to write these checks?
in thread Better way to write these checks?

Is that same as the OPs code?
No, it shows another technique of accomplishing the desired result.

Is @ARGV is a substitute for @_?
No. See perlvar. @ARGV holds the command line arguments given to the script, @_ holds the arguments given to the subroutine. Interestingly, operators like shift know to work on @_ inside subroutines and on @ARGV in the main execution block. So the following two scripts will show the same output:

printf "Got %s!\n", shift while @ARGV;
use subs qw(printfor); printfor @ARGV; sub printfor { my $f = shift; printf "Got %s!\n", shift while @_; }

Is print a substitute for return?
No. return is used inside subroutines to give back data to the calling code, print is used to generate output, which could be sent to the screen or a file handle, or it could be passed to function as another program's input using pipeline constructions. Among other things

Is a program a substitute for a subroutine?
Not really, although it's definitely possible to make another program do some work for you as if it were a subroutine. Shell scripting often works like that.


Comment on Re^3: Better way to write these checks?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-07-30 12:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (231 votes), past polls