|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
@old = ( 2, 5, 13, undef, 6, 8, undef, 3);
@new = ();
for ($i=0;$i<=$#old;$i++)
{
$new[$n++] = $old[$i] if defined $old[$i]; }
print "\n@old";
print "\n\n@new\n\n";
1
2
3
4
5
6
7
8
$i=0;
foreach (@old)
{ if ($old[$i] != defined)
{ splice @old,$old[$i],1; }
$i++;
}
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
31
32
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @old = ( 2, 5, 13, undef, 6, 8, undef, 3);
# mit splice (rückwärts durch das Array)
for (reverse 0..$#old) {
warn "splicing: \@old[$_]" and splice @old, $_, 1 unless defined $old[$_];
}
print Dumper \@old;
# ohne Zählvariable
@old = ( 2, 5, 13, undef, 6, 8, undef, 3);
my @new = ();
for (@old) { push @new, $_ if defined $_ };
@old = @new;
print Dumper \@old;
# die perl-typische Variante
@old = ( 2, 5, 13, undef, 6, 8, undef, 3);
@old = grep { defined } @old;
print Dumper \@old;
|< 1 2 >| | 12 Einträge, 2 Seiten |