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

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2017-04-27 23:26 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (514 votes). Check out past polls.