Re: problem passing argument to function



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>.
.



Relevant Pages

  • Re: Exit Sub not exiting
    ... Hmm not sure how reimporting the code would fix it. ... error might stop with only an Exit Sub, ... Sub at the end to cmdDataLoad_Click and go through the whole thing ...
    (microsoft.public.excel.programming)
  • Re: unique record
    ... I will go and fix all the field names and go from there. ... > they're not part of the control names. ... >> Private Sub CheckIndex() ...
    (microsoft.public.access.forms)
  • [PATCH] update checkpatch.pl to version 0.11
    ... lets fix those whitespace errors spotted by checkpatch...] ... add a summary to the bottom of the main report ... sub top_of_kernel_tree { ... # Pre-scan the patch looking for any __setup documentation. ...
    (Linux-Kernel)
  • RE: Browse window in form.
    ... Is there a way to fix these? ... Change the line Function TestIt() to the following: ... Private Sub Command2_Click ... Do I just copy and paste the code into my VBA window? ...
    (microsoft.public.access.forms)
  • RE: Browse window in form.
    ... Is there a way to fix these? ... Change the line Function TestIt() to the following: ... Private Sub Command2_Click ... Do I just copy and paste the code into my VBA window? ...
    (microsoft.public.access.forms)