Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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 chanting in the Monastery: (5)
As of 2018-06-24 03:41 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.