Thread subroutine-referenz (10 answers)
Opened by Gast at 2009-04-03 11:29

Gast Gast
 2009-04-03 13:47
#120253 #120253
Thx, soetwas habe ich gesucht.

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
package Mobile_Phone_Config;
use warnings;
use strict;
use feature ':5.10';
use Term::ANSIColor;
require Exporter;
our @ISA = qw( Exporter );
our @EXPORT = qw( mobile_phone_config );

my $promt_color = 'magenta';
my $c_space = 2;

sub mobile_phone_config {
  my %config = (
        # ...           => ...,
        # ...           => ...,
        color_count     => sub { my $count = shift; return colored( sprintf( "%${c_space}s", $count ), $promt_color ); },
        print_promt     => sub { print "\n" . colored( ':', $promt_color ); },
        ungueltig       => sub { say " - Ungültige Eingabe - \n"; sleep 2; },
  );
  return %config;
}
#...
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
#!/usr/bin/perl
use warnings;
use strict;
use feature ":5.10";
use Mobile_Phone_Config;

my %config = mobile_phone_config();


*{ color_count } = $config{color_count};

#*ungueltig = *$config{ungueltig};

sub print_promt { $config{print_promt}->() };


print color_count( 10 );

#ungueltig();

print_promt();


Die auskommentierte Version hat nicht funktioniert.
Ich hatte es zuerst mit sub routine { &$config{sub_ref}() } probiert, was nicht funktioniert hatte.

View full thread subroutine-referenz