I can't do this:
#!/usr/bin/perl
use strict
print "Hello World\n"
but I can do this:
#!/usr/bin/perl
use integer
print "Hello World\n"
I can't do this:
#!/usr/bin/perl
use Lingua::Identify
print "Hello World\n"
but I can do this:
#!/usr/bin/perl
use Date::Easter
print "Hello World\n"
Exactly... what is going on around here? :-)
Preliminary testing seemed to reveal that the reason it would only work sometimes would be that it only worked when the module version number was equal or above 1 (see * in the bottom, for the reason), but there were exceptions (strict 1.03 not working and CPAN::Mini 0.20 working, for instance).
Finding the solution would probably involve looking into the modules, which I don't think I'm able to after the day I had :-)
This seems rather odd... :-)
* - a sample error:
Lingua::Identify version 1 required--this is only version 0.10 at usr/lib/perl5/5.8.4/Exporter/Heavy.pm line 121.
BEGIN failed--compilation aborted at ./script line 3.
Re:consult perldoc
cog on 2004-12-31T00:56:12
That makes sense. Now that I think about it, I don't know how I didn't get it at first...
But come to think about it again, what about CPAN::Mini (version 0.20) and strict?
Wait... strict was giving a different error...
I need to get some sleep... over and out, back again sometime tomorrow...:-)
It all depends on the &import
of a module.
Lingua::Identify uses Exporter which considers the parameter a version number and croaks because it's higher than the module's.
strict uses a custom importer which considers the number a non-existant pragma tag and croaks.
In case noone else defines an &import
, modules inherit &UNIVERSAL::import
. Interestingly, that one does differentiate between a literal number and an expression:
$ echo 'package Foo; our $VERSION = 0.1; 1;' > Foo.pm
$ perl -le'BEGIN { $a = 1 } use Foo $a'
$ perl -le'use Foo print'
$ perl -le'use Foo 1'
Foo version 1 required--this is only version 0.1 at -e line 1.
BEGIN failed--compilation aborted at -e line 1.
use
statement.
#!/usr/bin/perl
use strict print "Hello World\n"
use strict 1.0
,
whereby the module is required to be at least version 1.0
#!/usr/bin/perl
use strict;
print "Hello World\n";
Re: Is this a bug i Perl?
cog on 2005-01-01T21:15:05
That was the precise point, the fact that the code would work some of the times without the semicolon:-) The part of the version one was taken care of pretty quickly, but it took Aristotle to find out the reason for the exceptions (that is, modules below version 1 working and vice-versa).
You wouldn't believe how ashamed of myself I am for not having solved the problem before posting it... oh well, one learns new things everyday
:-) Anyway, if that's what it takes to bring a new user to the site, you can all count of me to do it again... O:-)
Cheers, and welcome
:-)