Re: Making strict optional
by davorg (Chancellor) on May 31, 2006 at 15:02 UTC
|
You're asking the wrong question. strict.pm was included in Perl 5.005. If your installation doesn't have it then your installation is badly broken and can't be trusted. I recommend getting Perl reinstalled on that server as a matter of some urgency. You shouldn't be trying to work around its problems.
If you can't get Perl reinstalled then I recommend getting a new hosting company, sysadmin or job as appropriate.
--
< http://dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
| [reply] |
|
|
I'm currently on contract with the sysadmin group at this random large corporation, so I suppose I'm in as good of a position as anyone to try to get it fixed. I expect the attempt to fail, thanks to their paranoid change management policies, but, if it does fail, my contract runs out in a month, so I'll be getting a new job anyhow.
| [reply] |
Re: Making strict optional
by gellyfish (Monsignor) on May 31, 2006 at 15:04 UTC
|
Well perl 5.00502 as that message indicates the version in question is certainly did have strict I have a horrible feeling that you are going to find something even worse wrong with the perl installation even if you fix that, I suspect that they probably have just copied the perl binary without the libraries or just a few of them.
Of course you could do something like:
BEGIN
{
eval
{
require strict;
};
strict->import() unless $@;
}
but I think you will find that you end up playing whack-a-mole with stuff like that until the perl installation is repaired.
/J\ | [reply] [d/l] [select] |
|
|
Your suspicion looks quite likely to be correct... After discovering that the host in question is also missing Sys::Hostname, I took a look at @INC and none of the directories it references (except '.', of course) even exist.
sigh.
| [reply] |
Re: Making strict optional
by Zaxo (Archbishop) on May 31, 2006 at 15:08 UTC
|
That's a very broken installation of perl. Perl 5.5 should have strict.pm installed with it. That's a fault the admin should correct.
Failing administrative sympathy, you can move a copy of strict.pm into your own space and tell perl to look there with the PERL5LIB environment variable.
| [reply] |
Re: Making strict optional
by dave_the_m (Monsignor) on May 31, 2006 at 15:05 UTC
|
Note that strict has been part of perl since 5.000. It looks like your HPUX 5.00502 installation is missing some stuff,
so strict may be the least of your problems.
Dave. | [reply] |
|
|
Just out of curiousity, what gave it away as HPUX? Are they the only ones who put it in /opt/.../PA-RISC?
| [reply] |
|
|
The most common OS that runs on PA-RISC is HP-UX. See the Wikipedia PA-Risc family entry for more.
| [reply] |
Re: Making strict optional
by Herkum (Parson) on May 31, 2006 at 15:03 UTC
|
eval 'use strict';
if ($@) { # If it cannot 'use strict' then it will put the error in $
+@
print "Cannot 'use strict', it appears to be missing\n";
}
Put this in your code, and it will print a message if it cannot load strict for whatever reason. You can take out the message if you want.
Update: Put the {} for the eval command in the wrong place... Just taking them out altogether and removing it from the BEGIN block. At least I learned something today. | [reply] [d/l] |
|
|
strict ends here
|
|
BEGIN { v
eval 'use strict';
warn("Cannot 'use strict', it appears to be missing\n") if $@;
}
On the other hand, the following works (and doesn't use eval EXPR):
BEGIN {
eval { require strict };
if ($@) {
warn("Cannot 'use strict', it appears to be missing\n");
} else {
strict->import();
}
}
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] |
|
|
BEGIN
{
eval
{
require strict;
};
strict->import() unless $@;
}
+
$foo = 1;
Gives rise to:
Global symbol "$foo" requires explicit package name at hdhd line 10.
Execution of hdhd aborted due to compilation errors.
So no it does work.
Update: but of course the string eval is different.
/J\ | [reply] [d/l] [select] |
|
|
The problem with that is that the following script compiles without complaints (even when strict is available) and prints "5".
sub BEGIN {
{ eval 'use strict' }
}
$not_declared = 5;
print $not_declared, "\n";
"use strict" is always local for the surrounding block, so you cannot put it into eval or BEGIN. | [reply] [d/l] |
| A reply falls below the community's threshold of quality. You may see it by logging in. |