push %hash, key => "value"; push %hash, @ary;みたいに、ハッシュに対してもpush()を使えたら便利じゃないだろうか。とりあえず以下のコードで期待通りに動くはず。
use subs qw(push);
sub push (\[@%]@)
{
my $targ = shift;
my $type = ref $targ;
if ($type eq 'ARRAY') {
CORE::push @$targ, @_;
} elsif ($type eq 'HASH') {
while (my ($k, $v) = splice @_, 0, 2) {
$targ->{$k} = $v;
}
}
}
Comment
コメントする