Leser: 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/perl -W use strict; use warnings; use diagnostics; use Fcntl qw(:DEFAULT :flock); use Data::Dumper; local $Data::Dumper::Sortkeys = \&dumper_sort; sub dumper_sort { my ($hash) = @_; return [(sort {lc $a cmp lc $b} keys %$hash)]; } my %test = ( 1 => 'foo', 2 => 'bar', 3 => 'foobar', 4 => 'barfoo', ); my $loesche = 2; print Dumper (\%test); if ($loesche == keys %test) { delete $test{$loesche}; } else { for ($loesche + 1..keys %test) { $test{$_ - 1} = $test{$_}; delete $test{$_}; } } print Dumper (\%test);
1 2 3 4 5
my @list = $loesche .. keys %test; my @save = delete @test{@list}; pop @list; shift @save; @test{@list} = @save;
1 2
my @list = $loeschen .. keys %test; (undef, @test{ @list[0 .. $#list-1] }) = delete @test{@list};