On Wed, 31 Oct 2001, Roy Peters wrote:
> Is there any way to return 2 or 3 scalar variables from a subroutine (like
> passing a variable by reference in C)?
>
> I would like to avoid returning an array, if possible, because it makes
> the script very non-intuitive.
In what ways does it make it n
From: Roy Peters <[EMAIL PROTECTED]>
> Is there any way to return 2 or 3 scalar variables from a subroutine
> (like passing a variable by reference in C)?
>
> I would like to avoid returning an array, if possible, because it
> makes the script very non-intuitive.
Sorry? You th
this code just returns a reference to a scalar, which is rather pointless in
this case and really doesn't solve the problem.
> sub return_scalars {
> $scal1 = 5; Assign values to scalars somehow
> $scal2 = 7;
> return \$scal1, \$scal2;
> }
>
> ($test_scalar1, $test_scalar2) = &return_scalars();
On Oct 31, Roy Peters said:
>Is there any way to return 2 or 3 scalar variables from a subroutine (like
>passing a variable by reference in C)?
>
>I would like to avoid returning an array, if possible, because it makes
>the script very non-intuitive.
Subroutines can return any number of argumen
If I understand your question correctly, this will work:
#!/usr/bin/perl -w
use strict;
my ($a, $b, $c, $one, $two, $three);
$a=1; $b=2; $c=3;
($one, $two, $three)=Change($a, $b, $c);
print "$one $two $three\n";
sub Change {
my ($x, $y, $z)=@_;
$x++;
$y=0;
$z=10;
return ($x, $y, $z
sub return_scalars {
$scal1 = 5; Assign values to scalars somehow
$scal2 = 7;
return \$scal1, \$scal2;
}
($test_scalar1, $test_scalar2) = &return_scalars();
-Original Message-
From: Roy Peters [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 31, 2