On Apr 10, Richard Heintze said:

>I'm passing a singularly dimensioned array to a
>function. I need to clear the array in the function so
>that when I return to the main program, there are no
>entries in the array variable I passed to the
>function.

You have to pass the array by reference, then.

  my @array = (1 .. 4);

  print "(@array)\n";  # (1 2 3 4)
  my_func([EMAIL PROTECTED]);
  print "(@array)\n";  # ()

  sub my_func {
    my $array_ref = shift;
    @$array_ref = ();
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to