in reply to Duplicate variable returned from sub

your error message tells you "my" variable $var1 masks earlier declaration in same statement... This has nothing to do with the function. Fix the declaration, and the assignment will work as you expect.
use strict; use warnings; sub someFunction { return @{$_[0]} } my ($var1, $var2, $var3); my $var4 = [qw(1 2 3 4)]; ($var1, $var2, $var3, $var1) = someFunction($var4); print "$var1 $var2 $var3\n"; OUTPUT: 4 2 3
Bill

Replies are listed 'Best First'.
Re^2: Duplicate variable returned from sub
by Zenzizenzizenzic (Pilgrim) on Sep 23, 2019 at 21:01 UTC
    This was more for knowing the way Perl handled the situation, in case I need an immediate fix. I am changing the function itself. No errors/warnings given as the code was NUWNUS.