Thread [php] Präfixe aus Liste herausarbeiten (6 answers)
Opened by tim at 2012-11-05 11:33

Gast Tim
 2013-03-04 13:30
#166200 #166200
Aufgabenstellung ist, folgenden Perl Code in php umzuschreiben:

Code: (dl )
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
use warnings;
use strict;

my @data = qw(
# ...
);
my @new;
my @data_tmp = @data;

while (1) {
my %test;
@new = ();

for my $item (@data_tmp) {
next if $item !~ /^\d{2,}$/;
my $suffix = chop($item);
$test{$item}{$suffix}++;
}

for my $base (keys %test) {
if (scalar(keys %{$test{$base}}) == 10) {
push @new, $base;
}
else {
push @new, $base.$_ for keys %{$test{$base}};
}
}
last if $#new == $#data_tmp;
@data_tmp = @new;
}

print "$_\n" for sort @new;

Last edited: 2013-03-04 13:41:19 +0100 (CET)

View full thread [php] Präfixe aus Liste herausarbeiten