Leser: 1
|< 1 2 3 >| | 29 Einträge, 3 Seiten |
1
2
3
4
5
use HelloWorld;
my $greeting = HelloWorld->new();
$greeting->set('text', 'Hello World');
$greeting->say($greeting->get('text'));
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
39
40
41
42
43
44
package HelloWorld;
use strict;
use warnings;
use lib qw(.);
use Greetings ($0);
use String;
#Erzeugen
sub new {
my ($class,@params) = @_;
my $self = {};
bless($self,$class);
return($self);
}
sub set
{
my ($self,$var, $value ) = @_;
$self->{$var} = $value;
}
sub get
{
my ($self,$var) = @_;
return $self->{$var};
}
sub say
{
my ($self,$value) = @_;
print $value;
}
#alternativ
sub say2
{
my ($self,$value) = @_;
print $self->{text};
}
1
2
3
4
5
6
7
my $hello = HelloWorld->new;
$hello->{text} = "Hello World!\n";
$hello->greet;
package HelloWorld;
sub new { bless {} }
sub greet { print shift->{text} }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use strict;
use warnings;
package String;
sub new {
my ($class, $data) = @_;
bless \$data, $class
}
sub println {
print "${shift()}\n";
}
package main;
my $msg = new String("Hello World!");
$msg->println();
|< 1 2 3 >| | 29 Einträge, 3 Seiten |