Leser: 2
4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package Stats;
use strict;
use warnings;
use Carp qw/croak/;
sub new {
ref (my $class = shift) && croak 'class name needed in constructor';
my $self = {@_};
bless $self, $class;
}
sub alive {
my $self = shift;
for (my ($k, $v) = each(%$self) ) {
print "$k has the value $v\n";
}
}
1;
perl -MStats -e '$x = Stats->new(-test => 'bla', -test2 => 'blubb'); $x->alive();'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ perl -wle'
my %h = (a => 23, b => 24, c => 25);
print "while";
while (my ($k, $v) = each %h) {
print "$k => $v";
}
print "for";
for (my ($k, $v) = each %h) {
print "$k => $v";
}
'
while
c => 25
a => 23
b => 24
for
c => 25
c => 25
4 Einträge, 1 Seite |