1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl -w use strict; use warnings; my %foo; foreach $foo{zaehler} (0..10) { test (\%foo); } sub test { my ($bar) = @_; print "habe " . $bar -> {zaehler} . "\n"; }
1 2 3 4 5 6 7 8
my %foo; for ( $foo{zaehler} = 0; $foo{zaehler} <= 10; $foo{zaehler}++ ) { test (\%foo); } sub test { my ($bar) = @_; print "habe " . $bar -> {zaehler} . "\n"; }
2011-05-25T15:04:39 TaulmarillDas geht mit der guten alten for-Schleife im C-Style:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl -w use strict; use warnings; my %foo = ( test => { alpha => 'beta', gamma => 'delta', }, ); foreach $foo{zaehler} (keys %{$foo{test}}) { test (\%foo); } sub test { my ($bar) = @_; print "habe " . $bar -> {zaehler} . "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl -w use strict; use warnings; my %foo = ( test => { alpha => 'beta', gamma => 'delta', }, ); foreach my $nr (keys %{$foo{test}}) { $foo{zaehler} = $nr; test (\%foo); } sub test { my ($bar) = @_; print "habe " . $bar -> {zaehler} . "\n"; }
2011-05-25T15:16:32 biancaHab jetzt einfach Zeile 12 eingeschoben
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use strict; use warnings; my %foo = ( test => { alpha => 'beta', gamma => 'delta', }, ); while ( ( $foo{zaehler}, undef ) = each %{$foo{test}} ) { test (\%foo); } sub test { my ($bar) = @_; print "habe " . $bar -> {zaehler} . "\n"; }
2011-05-25T15:20:56 TaulmarillUnd dabei hatte ich gerade so eine schöne Lösung gefunden:
1 2 3 4 5 6 7 8 9
while(each %ENV){ $ENV{__COUNT__}++; test(\%ENV); } sub test{ my $ref = shift; print "$ref->{__COUNT__}\n"; }