images/napali.gifNapali.ch /perl

..

#!/usr/bin/perl -w
use strict;
use warnings;

my $i;

print "#" for ( 1 .. 30);
print "\nanonyme Arrays:\n";

my $table =
[
    [ 1, 2, 3],
    [ 4, 5, 6],
    [ 7, 8, 9],
];
my $x=1;
my $y=2;
print $table->[$x][$y] . "\n";


print "#" for ( 1 .. 30);
print "\nanoyme Hashes:\n";

my $personen =
{
   #ID
   0    => { Name => "Schneider", Vorname => "Sepp",  Alter => 40 },
   1    => { Name => "Wagner",    Vorname => "Vreni", Alter => 23 },
   2    => { Name => "Lauch",     Vorname => "Leo",   Alter => 29 },
   3    => { Name => "Studer",    Vorname => "Oscar", Alter => 78 },
};

$i=0;
while ( defined ( $personen->{$i}{Name} ) ) {
  print $i . ": $_: " . $personen->{$i}{$_} . "\n" for qw( Name Vorname Alter );
  $i++
}

undef $personen;


print "#" for ( 1 .. 30);
print "\nkomplexe hash of array of hash of array Datenstruktur:\n";

$personen = {
             'person' => [
                           {
                             'email'   => [ 'h.m@example.org' ],
                             'vorname' => [ 'Hans' ],
                             'alter'   => [ '12' ],
                             'name'    => [ 'Meier' ],
                             'adresse' => [ 
                                            {
                                              'ort'     => [ 'Aarau' ],
                                              'strasse' => [ 'Hauptstrasse 5' ],
                                              'plz'     => [ '5001' ]
                                            }
                                          ]
                           },
                           {
                             'email'   => [ 'anna.richner@gmx.ch' ],
                             'vorname' => [ 'Anna' ],
                             'alter'   => [ '34' ],
                             'name'    => [ 'Richner' ],
                             'adresse' => [
                                            {
                                              'ort'     => [ 'Rohr' ],
                                              'strasse' => [ 'Hofweg 5' ],
                                              'plz'     => [ '5032' ]
                                            }
                                          ]
                           },
                           {
                             'email'   => [ 'stotz@gmx.ch' ],
                             'vorname' => [ 'Urs' ],
                             'alter'   => [ '37' ],
                             'name'    => [ 'Stotz' ],
                             'adresse' => [
                                            {
                                              'ort'     => [ 'Olten' ],
                                              'strasse' => [ 'Sonnhaldenstrasse 10' ],
                                              'plz'     => [ '4600' ]
                                            }
                                          ]
                           }
                         ],
           };
print $personen->{"person"}[1]{"name"}[0] . ":" . 
      $personen->{"person"}[1]{"vorname"}[0] . ":" .
      $personen->{"person"}[1]{"adresse"}[0]{"ort"}[0] . "\n";

$i=0;
while ( defined ( $personen->{"person"}[$i]{"name"}[0] ) ) {
  print $i . ": $_: " . $personen->{"person"}[$i]{$_}[0] . "\n" for qw( name vorname alter );
  $i++
}

undef $personen;


print "#" for ( 1 .. 30);
print "\nkomplexe hash of hash of hash of hash Datenstruktur:\n";

$personen= {
             'person' => {
                           'Stotz' => {
                                        'email'   => 'stotz@gmx.ch',
                                        'vorname' => 'Urs',
                                        'alter'   => '37',
                                        'adresse' => {
                                                       'ort'     => 'Olten',
                                                       'strasse' => 'Sonnhaldenstrasse 10',
                                                       'plz'     => '4600'
                                                     }
                                      },
                           'Meier' => {
                                        'email'   => 'h.m@example.org',
                                        'vorname' => 'Hans',
                                        'alter'   => '12',
                                        'adresse' => {
                                                       'ort'     => 'Aarau',
                                                       'strasse' => 'Hauptstrasse 5',
                                                       'plz'     => '5001'
                                                     }
                                      },
                         'Richner' => {
                                        'email'   => 'anna.richner@gmx.ch',
                                        'vorname' => 'Anna',
                                        'alter'   => '34',
                                        'adresse' =>
                                                     {
                                                       'ort'     => 'Rohr',
                                                       'strasse' => 'Hofweg 5',
                                                       'plz'     => '5032'
                                                     }
                                      }
                         },
           };

print "$_: " . $personen->{'person'}{'Stotz'}{$_} . "\n" for qw( vorname email alter);

__END__

##############################
anonyme Arrays:
6
##############################
anoyme Hashes:
0: Name: Schneider
0: Vorname: Sepp
0: Alter: 40
1: Name: Wagner
1: Vorname: Vreni
1: Alter: 23
2: Name: Lauch
2: Vorname: Leo
2: Alter: 29
3: Name: Studer
3: Vorname: Oscar
3: Alter: 78
##############################
komplexe hash of array of hash of array Datenstruktur:
Richner:Anna:Rohr
0: name: Meier
0: vorname: Hans
0: alter: 12
1: name: Richner
1: vorname: Anna
1: alter: 34
2: name: Stotz
2: vorname: Urs
2: alter: 37
##############################
komplexe hash of hash of hash of hash Datenstruktur:
vorname: Urs
email: stotz@gmx.ch
alter: 37