Leser: 29
eval { require Net::FTP; };
if ($@)
1 2 3 4 5 6 7 8 9 10
my $ftp; BEGIN { eval { require Foo; }; # oder eval "use Foo" $ftp = 1 unless $@; } if ($ftp) { }
Useless use of a constant in void context at [gekürzt]/script.pl line 26., referer: [gekürzt]/script.pl
1 2 3 4 5 6 7
my $parser; BEGIN { eval { "use Parse::HTTP::UserAgent" }; $parser = 1 unless $@; }
eval "use Modul; 1;" or die $@; # kein Block-eval
2009-12-26T09:57:36 reneeCode (perl): (dl )eval "use Modul; 1;" or die $@; # kein Block-eval
2010-02-06T13:12:01 reneeDas passiert erst zur Laufzeit, quasi wie ein require (obwohl hier das "use" auch den import macht).
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
jars@jars-desktop$ perl -MData::Dumper -le 'print Dumper \%INC; if ( eval "use CGI;1;" ) { print Dumper \%INC }; '
$VAR1 = {
'warnings/register.pm' => '/usr/share/perl/5.8/warnings/register.pm',
'bytes.pm' => '/usr/share/perl/5.8/bytes.pm',
'XSLoader.pm' => '/usr/lib/perl/5.8/XSLoader.pm',
'Carp.pm' => '/usr/share/perl/5.8/Carp.pm',
'Exporter.pm' => '/usr/share/perl/5.8/Exporter.pm',
'warnings.pm' => '/usr/share/perl/5.8/warnings.pm',
'overload.pm' => '/usr/share/perl/5.8/overload.pm',
'Data/Dumper.pm' => '/usr/lib/perl/5.8/Data/Dumper.pm'
};
$VAR1 = {
'warnings/register.pm' => '/usr/share/perl/5.8/warnings/register.pm',
'bytes.pm' => '/usr/share/perl/5.8/bytes.pm',
'XSLoader.pm' => '/usr/lib/perl/5.8/XSLoader.pm',
'Carp.pm' => '/usr/share/perl/5.8/Carp.pm',
'vars.pm' => '/usr/share/perl/5.8/vars.pm',
'strict.pm' => '/usr/share/perl/5.8/strict.pm',
'Exporter.pm' => '/usr/share/perl/5.8/Exporter.pm',
'constant.pm' => '/usr/share/perl/5.8/constant.pm',
'warnings.pm' => '/usr/share/perl/5.8/warnings.pm',
'CGI/Util.pm' => '/usr/local/share/perl/5.8.8/CGI/Util.pm',
'overload.pm' => '/usr/share/perl/5.8/overload.pm',
'CGI.pm' => '/usr/local/share/perl/5.8.8/CGI.pm',
'Data/Dumper.pm' => '/usr/lib/perl/5.8/Data/Dumper.pm'
};
jars@jars-desktop$
2009-12-26T09:57:36 reneeWenn dann müsste esCode (perl): (dl )eval "use Modul; 1;" or die $@; # kein Block-eval
2010-02-06T13:45:50 EscapeUnd dabei (also kein Block-eval) wird tätsächlich $@ zurückgeliefert?
1 2
my $browser_parser = 1; eval "use HTTP::DetectUserAgent; 1;" or $browser_parser = 0;
perldoc -f evalIf there is a syntax error or runtime error, or a die statement is executed, eval returns an undefined value in scalar context or an empty list in list context, and $@ is set to the error message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
BEGIN { eval "use ModulX"; } if (ModulX->can('Methode')) { print "CAN:\n" #... ModulX::Methode(); #... } else { print "CANT\n"; }
Class::MOP::load_class($class_name)