in reply to technique of push
You either need to do something with the return value or act on a reference to the array rather than a copy of it.#!/usr/bin/perl use strict; use warnings; sub push1{ my $ref=shift; my @a=@{$ref}; my $s=shift; my $len=@a; $a[$len]=$s; return \@a; } sub push2{ my $ref=shift; my $s=shift; my $len=@{$ref}; $ref->[$len]=$s; return ; } my @a=qw( 1 2 3 4 ); push1(\@a,5); print "Using push1 ", @a,"\n"; @a=qw( 1 2 3 4 ); push2(\@a,5); print "Using push2 ", @a,"\n"; Using push1 1234 Using push2 12345
|
|---|