$foo.append($bar);
@foo.append(@bar);
%foo.append(%bar);
####
$foo.prepend($bar);
@foo.prepend(@bar);
%foo.prepend(%bar);
##
##
# append($x, $y) appends $y to $x
# etc.
# prepend() left as a simple exercise to the reader
sub append (\[$@%]\[$@%]) {
use Scalar::Util 'reftype';
use Carp qw( croak );
my ($l, $lt, $r, $rt) = map { $_, reftype($_) } @_;
if ($lt eq $rt) {
if ($lt eq 'SCALAR') {
$$l .= $$r;
}
elsif ($lt eq 'ARRAY') {
push @$l, @$r;
}
elsif ($lt eq 'HASH') {
@$l{keys %$r} = values %$r;
}
else {
croak "append($lt,$rt) not implemented";
}
}
else {
croak "append($lt,$rt) not implemented";
}
}