Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Better way to write these checks?

by muba (Priest)
on Jun 29, 2012 at 15:52 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found