QuoteWARNING: Calling "delete" on array values is strongly
discouraged. The notion of deleting or checking the existence of
Perl array elements is not conceptually coherent, and can lead
to surprising behavior.
2018-12-10T18:05:53 rostidelete macht den Eintrag zu undef. Anstatt zu löschen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use Data::Dumper; $Data::Dumper::Sortkeys = 1; use strict; use warnings; use Tie::Array; use base qw(Tie::StdArray); tie my @arr, 'main'; @arr = qw(foo bar baz); delete $arr[0]; print Dumper \@arr; sub DELETE{ my $self = shift; my $idx = shift; splice @$self, $idx, 1; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use Data::Dumper; $Data::Dumper::Sortkeys = 1; use strict; use warnings; use Tie::Array; use base qw(Tie::StdArray); tie my @arr, 'main'; @arr = qw(foo bar baz); # Extrahiere die Instanz tied(@arr)->rm(0); # remove alias delete print Dumper \@arr; sub rm{ my $self = shift; my $idx = shift; splice @$self, $idx, 1; }