1 2 3 4
foreach my $key (keys %allCustomers) { my $customer = $allCustomers{$key}; say $customer->{foo}; ...
1 2 3 4
foreach my $key (keys %allCustomers) { my %customer = %{ $allCustomers{$key} }; say $customer{foo}; ...
1 2 3 4 5 6 7 8 9 10 11 12 13
sub einlesen { $count = 0; $db->Sql("select * from customers"); while ($db->FetchRow()) { $customer{'customerId'} = $db->Data("kundennummer"); $customer{'street'} = $db->Data("strasse"); $customer{'streetNumber'} = $db->Data("hausnummer"); $customer{'city'} = $db->Data("ort $allCustomers{$count} = \%ddvCustomer; $count++; } return %allCustomers; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$VAR1 = '127';
$VAR2 = {
'customerId' => 1234,
'street' => 'Hauptstr.',
'streetNumber' => '33',
'city' => 'Musterort'
};
$VAR3 = '1049';
$VAR4 = $VAR2;
$VAR5 = '71';
$VAR6 = $VAR2;
$VAR7 = '1648';
$VAR8 = $VAR2;
...
1 2 3 4
foreach my $key (%allCustomers) { my %customer = %{ $allCustomers{$key} }; print $customer{'customerId'} . " "; }
foreach my $key (%allCustomers) {
foreach my $key (keys %allCustomers) {
1 2
foreach my $key (keys %allCustomers) { print $key . "-" . $allCustomers{$key}{'customerId'} . "\n";}
1 2 3 4 5 6 7 8 9 10 11 12 13
sub einlesen { $count = 0; $db->Sql("select * from customers"); while ($db->FetchRow()) { $customer{'customerId'} = $db->Data("kundennummer"); $customer{'street'} = $db->Data("strasse"); $customer{'streetNumber'} = $db->Data("hausnummer"); $customer{'city'} = $db->Data("ort $allCustomers{$count} = \%Customer; ## Linuxer "ddv" removed from \%ddvCustomer $count++; } return %allCustomers; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
sub einlesen { # no global $count my $count = 0; $db->Sql("select * from customers"); while ($db->FetchRow()) { # new hash for each Row my %customer = ( 'customerId' => $db->Data("kundennummer"), 'street' => $db->Data("strasse"), 'streetNumber' => $db->Data("hausnummer"), 'city' => $db->Data("ort}, ); $allCustomers{$count++} = \%Customer; ## Linuxer "ddv" removed from \%ddvCustomer } return %allCustomers; }
Guest BastiPS: in meinem letzten Eintrag steht da von mir fehlerhaft "\%ddvCustomer". Das ist meinem Test im zweiten Editorfenster geschuldet. Es heißt im echten Programm immer "\%customer"