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

bianca
 2015-02-20 15:04
#179783 #179783
User since
2009-09-13
7016 Artikel
BenutzerIn

user image
Implementiert sähe das dann 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
#!/usr/bin/perl
use strict;
use warnings;
use 5.010.000;
use File::Basename qw( basename );

my @dispatchtab = (
    {
        moduldatei      => 'test_extern.pl',
        aufruf_sub      => \&testsub,
        aufruf_neu      => 'testsub',
        unit            => 'unit1',
    },
    {
        moduldatei      => 'test_extern2.pl',
        aufruf_sub      => \&testsub,
        aufruf_neu      => 'testsub',
        unit            => 'unit2',
    },
    # hier sind natürlich noch ganz viele
);
for my $ref ( @dispatchtab ) {
  # clean up file name for usage as namespace name (remove file path and extension and convert '-' to '_')
  ( my $namespace = basename( $ref->{moduldatei}, '.pl' ) ) =~ tr/-/_/;

  eval <<"EVAL_CODE";
package $namespace;                     # declare package to contain imported functions
require "$ref->{moduldatei}";                 # "import" function(s)
$ref->{aufruf_sub}('a');                # call function with string-eval; remember to insert error handling
                                        # We are inside package MyModule, so no need for package name in string
EVAL_CODE
        warn "$@\n"     if $@; 
}


Wirft leider:
Quote
syntax error at (eval 1) line 3, near ")("

syntax error at (eval 2) line 3, near ")("
10 print "Hallo"
20 goto 10

View full thread Bad name after...