> -----Original Message-----
> From: Batchelor, Scott [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 20, 2002 4:21 PM
> To: '[EMAIL PROTECTED]'
> Subject: Calling subroutines...
>
>
> Hi again all.
>
> I have a question about calling a subroutine in Perl. Here
> is what I am
> trying:
>
> Calling_sub($var1, $var2);
>
> sub calling_sub
Perl is cAsE sensitive, so you these two lines don't agree.
Also, the body of the sub needs to be enclosed in { }
>
> my $subvar = @_;
This doesn't do what you think it does. @_ is an array containing
the list of args passed to your sub by the caller. Since $subvar
is a scalar, this evaluates @_ in scalar context, returning the
number of args passed.
>
> my $subvar1 = $var1
Need a semicolon to separate this statement from the following.
>
> my $subvar2 = $var2
>
>
>
> Now my question is...Don't I need to somehow split the two
> variables that I
> passed to the subroutine so that I can use them separately?
The standard way is:
sub foo
{
my ($arg1, $arg2) = @_;
...blah...
}
or:
sub foo
{
my $arg1 = shift;
my $arg2 = shift;
...blah...
}
(The latter form taking advantage of the default behavior of
shift() when used in a sub to shift from @_).
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]