Thread Perl & RegEx (7 answers)
Opened by RalphFFM at 2020-02-01 17:50

hlubenow
 2020-02-01 20:23
#191253 #191253
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Ich würde das eher so angehen:
Code (perl): (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
33
34
35
36
#!/usr/bin/perl
use strict;
use warnings;

sub PythonDictStringToPerlHash {
    my $s = shift;
    my @a = split(/:/, $s);
    my $key = $a[0];
    $key =~ s/"//g;
    $key =~ s/ //g;
    my $b = $a[1];
    $b =~ s/\n//g;
    $b =~ s/"//g;
    $b =~ s/\[//g;
    $b =~ s/\]//g;
    $b =~ s/ //g;
    my @vals = split(/,/,$b);
    my %h;
    $h{$key} = \@vals;
    return \%h;
}

my $segmente = q( "nodes": [
    272447305,
    272447306,
    272447307,
    272447308,
    272447305
  ]);

my %h = %{PythonDictStringToPerlHash($segmente)};
my @hkeys = keys(%h);
my @zahlen = @{$h{$hkeys[0]}};
for my $i (@zahlen) {
    print "$i\n";
}

View full thread Perl & RegEx