Thread Perl Objekt orientierte Programmierung: objekte suchen und anzeigen (4 answers)
Opened by Gast at 2007-04-18 15:41

renee
 2007-04-18 15:58
#76027 #76027
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Ich verstehe zwar nicht so ganz, worauf Du hinaus willst, aber vielleicht hilft Dir das:

Code (perl): (dl )
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
package TestObjects;

use strict;
use warnings;

my @objects;

sub new{
    my ($class) = @_;
    my $self = {};
    bless $self,$class;
    push @objects,$self;
    return $self;
}

sub name{
    my ($self,$name) = @_;
    $self->{NAME} = $name if defined $name;
    return $self->{NAME};
}

sub properties{
    my ($self,@properties) = @_;
    $self->{PROPERTIES} = [@properties] if @properties;
    my @array;
    @array = @{$self->{PROPERTIES}} if defined $self->{PROPERTIES};
    return @array;
}

sub find{
    my ($class,$name) = @_;
    
    for my $obj( @objects ){
        if( $obj->name eq $name ){
            print $obj->name," -> ",join("..",$obj->properties),"\n";
        }
    }
}

1;


Skript:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl

use strict;
use warnings;
use TestObjects;

my $obj1 = TestObjects->new();
$obj1->name( 'Jason' );
$obj1->properties( 'a','b' );

my $obj2 = TestObjects->new();
$obj2->name( 'Hugo' );

TestObjects->find( 'Jason' );
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Perl Objekt orientierte Programmierung: objekte suchen und anzeigen