|< 1 2 >| | 16 Einträge, 2 Seiten |
my @array = gw(1 2 3 4 5 6);
1 2 3
sub _{s;;xrqIpiql\\{}p{pl{R>rl{N{}gjwpkssq]>rl{N;;;*{{}=*{_};; ${{}={q{{{}}}=>[reverse+split+reverse+q;}{;]};${{}->{q{{{}}}}->[@{{}];} ${{}=reverse+_(q{{}}=>q{{}})^chr(30)x+length&_(q{{}}=>,q{{}})and+print;
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
28
29
30
31
32
33
34
35
36
37
38
SUPER.pl
#!/usr/local/bin/perl -w
# SUPER.pl -- Zeigt die Verwendung der Pseudoklasse SUPER
package Base;
sub new {
my $cn = shift;
my $data = shift;
my $self = { data => $data };
return bless $self, $cn;
}
sub mytype {
my $self = shift;
return ref($self);
}
package Derived1;
@ISA = qw(Base);
sub new {
my $cn = shift;
my $data = shift;
my $moredata = shift;
my $self = $cn->SUPER::new($data);
$self->{'moredata'} = $moredata;
return $self;
}
sub mytype {
my $self = shift;
return ref($self);
}
package main;
my $obj = Derived1->new("data1", "data2");
print "Type: ", $obj->mytype(), "\n";
print "Data1:", $obj->{'data'}, "\n";
print "Data2:", $obj->{'moredata'}, "\n";
1 2 3 4 5
Listen von Zeichenkettenliteralen wie ("blood","sweat","tears") sind ziemlich schwierig zu tippen und lesen. Perl stellt deshalb einen speziellen Operator (gw) zur Verfügung..... ($sanguine, $saline, $doleful) = qw(blood sweat tears); Wenn Sie als Listenklammern gw voranstellen, können Sie die Gänsefüßchen und die Kommata weglassen.
1 2 3
sub _{s;;xrqIpiql\\{}p{pl{R>rl{N{}gjwpkssq]>rl{N;;;*{{}=*{_};; ${{}={q{{{}}}=>[reverse+split+reverse+q;}{;]};${{}->{q{{{}}}}->[@{{}];} ${{}=reverse+_(q{{}}=>q{{}})^chr(30)x+length&_(q{{}}=>,q{{}})and+print;
..... oder sterbe;
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 28 29
package Settable; sub new { my($class,$set) = @_; my $self = { Settable_set => $set }; return bless $self, $class; } sub set { my ($self) = @_; $self->{Settable_set} = 1; } package Collection; @ISA = qw(Settable); sub new { my($class, %items) = @_; my $self = $class->SUPER::new(); self->{Collection_set} = { %items }; return $self; } sub list { my($self) = @_; print keys %{$self->{Collection_set}}; }
1 2 3
sub _{s;;xrqIpiql\\{}p{pl{R>rl{N{}gjwpkssq]>rl{N;;;*{{}=*{_};; ${{}={q{{{}}}=>[reverse+split+reverse+q;}{;]};${{}->{q{{{}}}}->[@{{}];} ${{}=reverse+_(q{{}}=>q{{}})^chr(30)x+length&_(q{{}}=>,q{{}})and+print;
|< 1 2 >| | 16 Einträge, 2 Seiten |