Thread Problem mit HASH ref (48 answers)
Opened by bianca at 2010-05-02 13:09

GwenDragon
 2015-07-23 15:40
#181651 #181651
User since
2005-01-17
14835 Artikel
Admin1
[Homepage]
user image
Weiß nicht was du tust.
Bei mir geht es so:


jjj.pl
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
use strict; 
use warnings;

use 5.018;

package jjj;

sub YYY {
    my $y = shift // q{ ~ \o/ ~ /o\ ~ \o/ };    
    say $y;
}

1;


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
41
42
43
44
45
46
47
use strict; 
use warnings;

use 5.018;

my %dispatch = (
    lach => \&Booh::laugh,
    foo   => \&main::bar,
    bar   => \&baz,
    yipp  =>\&jjj::YYY,
);

require "jjj.pl";

package Booh;

sub laugh {
    my $lach = shift // 'hahahahahahah';
    say $lach;
}

1; 

package main;

sub bar {
    my $knete = shift // 'is nich'; 
   say "Bar $knete aus der Kasse";
}

sub baz {
    say 'Bar und Baaaatz';
}

##########

my $coderef = Booh->can('laugh'); $coderef->('hihia'); # Boo::laugh(....)

$dispatch{lach}->('Gacker!!!!!!!!!!!!!!!'); # auch Boo::laugh(....)

$coderef = main->can('bar'); $coderef->(); $coderef->('100 EURO');

$coderef = jjj->can('YYY'); $coderef->(); $coderef->('Yippi');

$dispatch{'yipp'}->('hollaaaaaa');

1;

View full thread Problem mit HASH ref