Thread Textbasiertes RPG speichern (10 answers)
Opened by TDog at 2013-11-10 14:10

Gast wer
 2013-11-10 15:06
#171989 #171989
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Storable;
my $file="game.save";

{
  my $xp   = 1;
  my $name = "test";
  my $foo  = 123;
  my @bar  = qw(foo bar bam);
  my %bam  = ( a => 1, b => 2, c => 3 );
  store([$xp,$name,$foo,\@bar,\%bam],$file);
}

{
  my($xp,$name,$foo,$bar_ref,$bam_ref)=@{retrieve($file)};
  my @bar = @$bar_ref;
  my %bam = %$bam_ref;
  print "($xp,$name,$foo,@bar,%bam)\n";
}


oder:
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
use Storable;
my $file="game.save";

{
  my $xp   = 1;
  my $name = "test";
  my $foo  = 123;
  my @bar  = qw(foo bar bam);
  my %bam  = ( a => 1, b => 2, c => 3 );
  store({
    xp   => $xp,
    name => $name,
    foo  => $foo,
    bar  => \@bar,
  },$file);
}

{
  my $hashref=retrieve($file);
  my $xp   = $hashref->{xp};
  my $name = $hashref->{name};
  my $foo  = $hashref->{foo};
  my @bar  = @{$hashref->{bar}};
  my %bam  = %{$hashref->{bam}};

  print "($xp,$name,$foo,@bar,%bam)\n";
}

Last edited: 2013-11-10 16:19:19 +0100 (CET)

View full thread Textbasiertes RPG speichern