Thread Perl-Modul nur einbinden, wenn auch installiert? (25 answers)
Opened by x-man at 2007-01-05 01:16

PerlProfi
 2007-01-05 14:35
#9459 #9459
User since
2006-11-29
340 Artikel
BenutzerIn
[default_avatar]
Ich glaube nicht, dass er die Meldung meinte, die beim die() rauskommt.
Wenn doch, dann verstehe ich nicht ganz, was du denn eigentlich wolltest.

Allerdings habe ich gerade auch mal deine beiden code stücke ausprobiert, und das erste funktioniert bei mir sehr gut.
Beim zweiten ist ja klar, dass die Fehlermeldung da von Perl kommt, wenn du kein GD hast.

edit:
Vielleicht meintest du eher soetwas:
Code: (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
#!/usr/bin/perl
use strict;
use warnings 'all';

# we need GD
eval { require GD };
unless ($@)
{
# if GD is installed, call GD::import
import GD;

# and start
start();
}
else
{
# exit with errorlevel > 0
exit(1);
}

# all was right, so exit with errorlevel == 0
exit(0);

# start here(GD is installed)
sub start
{
print "Content-type: image/png\n\n";

my $image = new GD::Image(100,20);
my $rot = $image->colorAllocate(255,0,0);
my $weiss = $image->colorAllocate(255,255,255);

$image->string(GD::gdMediumBoldFont(),3,5,"Test",$weiss);
binmode STDOUT;
print $image->jpeg;
} # start

__END__

Ich habe noch GD vor und () nach gdMediumBoldFont gesetzt, weil das ja eine Funktion ist, die nicht standardmäßig exportiert wird, und ohne die () als Bareword erkannt wird.

MfG PerlProfi\n\n

<!--EDIT|PerlProfi|1168001280-->

View full thread Perl-Modul nur einbinden, wenn auch installiert?