Re: problem passing argument to function
- From: a.r.ferreira@xxxxxxxxx (Adriano Ferreira)
- Date: Wed, 28 Dec 2005 09:23:48 -0200
On 12/28/05, Khairul Azmi <khairul.azmi@xxxxxxxxx> wrote:
> That one works using a solution
> I found on the web but the problem is when I tried to pass the argument to a
> function declared in the same file, the argument somehow became null.
> sub sample_function {
> print "go in $_\n"; <----- $_ is not the first argument, which is $_[0]
> }
> sample_function($line); <---- when passing the arguments,
the callee will
see @_ = ($line)
So you probably fix your code, by doing
sub sample_function {
print "go in $_[0]\n";
}
or
sub sample_function {
my $arg = shift; # removes the first element of @_ and returns it
print "go in $arg\n";
}
It is all there in C<perldoc perlsub>.
.
- References:
- problem passing argument to function
- From: Khairul Azmi
- problem passing argument to function
- Prev by Date: problem passing argument to function
- Next by Date: spwaned process using expect getting killed
- Previous by thread: problem passing argument to function
- Next by thread: spwaned process using expect getting killed
- Index(es):
Relevant Pages
|
|