You can have your cake and eat it too :)
Use a prototype to avoid the backslash and assign the reference to a localised glob to avoid teh need to dereference in the sub.
#! perl -sw
use strict;
sub setmode ($\@) { ## the prototype makes the reference
our @array; ## satisfy strict
my $val = shift;
local *array = shift; ## alias the reference
splice @array, 1, 0, $val; ## do normal array operations
}
my @a = qw( one two three );
print join( "\n", @a ), "\n__________\n";
setmode 'add_test', @a;
print join( "\n", @a );
__END__
[ 7:19:41.56] P:\test>junk3
one
two
three
__________
one
add_test
two
three
Whether the effort is worth may depend upon how much dereferencing you will do in the sub, and possibly whether the elements of the array might need further dereferencing.
Whether using prototypes, our and local is acceptable will depend upon your personal or corporate "acceptably unconfusing and mainatainable subset" of Perl's facilities and syntax.
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
|