Thread XML::Simple - XML bearbeiten und speichern (12 answers)
Opened by guenni at 2013-02-27 12:15

Muffi
 2013-02-27 23:58
#166069 #166069
User since
2012-07-18
1465 articles
BenutzerIn
[default_avatar]
Das level muss man mit abspeichern

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
my @todos = map { { data => $_, level => 1 } } @{$data->{data}};

while (@todos) {
    my $todo = pop @todos;
    print "id: ", $todo->{data}{id}, "\n";
    print "level: ", $todo->{level}, "\n";
    if (exists $todo->{data}{data}) {
        push @todos, map { { data => $_, level => $todo->{level} +1 } } @{$todo->{data}{data}};
    }
}


[EDIT] hübscher (2mal map ersetzt)

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
my @todos = ();
push @todos, { data => $_, level => 1 } for @{$data->{data}};

while (@todos) {
    my $todo = pop @todos;
    print "id: ", $todo->{data}{id}, "\n";
    print "level: ", $todo->{level}, "\n";
    if (exists $todo->{data}{data}) {
        push @todos, { data => $_, level => $todo->{level} +1 } for @{$todo->{data}{data}};
    }
}

Last edited: 2013-02-28 15:21:13 +0100 (CET)
1 + 1 = 10

View full thread XML::Simple - XML bearbeiten und speichern