Thread serial, dump - Komplexe Datenstrukturen speichern und ausgeben (12 answers)
Opened by mika at 2012-03-03 14:55

hlubenow
 2012-03-03 23:27
#156597 #156597
User since
2009-02-22
875 Artikel
BenutzerIn
[default_avatar]
Nochmal ein Beispiel:
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
#!/usr/bin/perl

use warnings;
use strict;

use YAML;

# hash to YAML:
my %hash = (name => "Ken",
            age  => 30);

my $hashref = \%hash;
my $dumpstring = Dump($hashref);

# Write YAML-file:
open(FH, ">storehash.txt") or die;
print FH $dumpstring;
close(FH);

# Read YAML-file:
open(FH, "<storehash.txt") or die;
my @a = <FH>;
close(FH);
my $b = join("\n", @a);

# YAML to hash:
my $hr = Load($b);
my %newhash = %{$hr};

foreach my $i (keys %newhash) {
    print "$i => $newhash{$i}\n";
}

View full thread serial, dump - Komplexe Datenstrukturen speichern und ausgeben