I have written a module which contains some oft used subroutines.
One routine is simply extracting data from a file into an array. I have written the code in a couple of ways, both seem to do the job ok:
# from wslib.pm sub gencli { open FH, '<', $gencli or die "Can't open $gencli $!"; flock (FH, 1) or die "Can't lock $gencli for reading: $!"; my @gencli = <FH>; close FH; return \@gencli; } #from script, subroutine call my $gencli_scalar = gencli(); my @gencli = @{ $gencli_scalar };
The other way
#from wslib.pm sub gencli { open FH, '<', $gencli or die "Can't open $gencli $!"; flock (FH, 1) or die "Can't lock $gencli for reading: $!"; @_ = <FH>; close FH; } #from script &gencli; my @gencli = @_; @_=();
In the former example can I get the scalar out of the subroutine without creating a sacrificial $gencli? Is the second way 'wrong'?
thank you
In reply to Extracting an array from a module by jonnyfolk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |