Thread Bad name after... (52 answers)
Opened by bianca at 2015-02-19 12:08

bianca
 2015-02-20 14:56
#179777 #179777
User since
2009-09-13
6975 Artikel
BenutzerIn

user image
Ich finde das toal schwer, deinen Code immer zu implementieren. Sieht jetzt mal so aus:
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
#!/usr/bin/perl
use strict;
use warnings;

my @dispatchtab = (
    {
        moduldatei      => 'test_extern.pl',
        aufruf_sub      => \&testsub,
        aufruf_neu      => 'testsub',
        unit            => 'test1',
    },
    {
        moduldatei      => 'test_extern2.pl',
        aufruf_sub      => \&testsub,
        aufruf_neu      => 'testsub',
        unit            => 'test2',
    },
    # hier sind natürlich noch ganz viele
);
my $arg = 0;
foreach my $ref (@dispatchtab) {
    my $packname = $ref->{unit};
    $packname =~ s/\W//g;
    my $source = do{
        my $fh = IO::File->new;
        $fh->open($ref->{moduldatei}, "r") or die $!;
        read($fh, my $buffer, -s $fh);
        $fh->close;
        "package $packname;\n".$buffer;
    };
    eval "$source" or die $@;
    my $coderef = $packname->can($ref->{aufruf_sub});

    $coderef->(++$arg);
}


Wirft aber leider
Quote
Use of uninitialized value in subroutine entry at test.pl line 34.
Use of uninitialized value in subroutine entry at test.pl line 34.
Can't use string ("") as a subroutine ref while "strict refs" in use at test.pl line 34.


Hab ich was falsch gemacht?
10 print "Hallo"
20 goto 10

View full thread Bad name after...