Re: Problems with 'our' definition with perl 5.00503
by BrowserUk (Patriarch) on Jun 30, 2005 at 01:03 UTC
|
If your uses of our can be substituted with my, why are you using our?
They are not interchangable. If you can use my wherever you are currently using our you should do so.
Otherwise, if your code has to run on 5.005, you could use vars q/ $x $y $z/; and that will run both pre- and post-5.6.
But really, you should only use our when you cannot use my.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] |
Re: Problems with 'our' definition with perl 5.00503
by tilly (Archbishop) on Jun 30, 2005 at 04:07 UTC
|
package strictitude;
require strict;
*unimport = \&strict::unimport;
sub import {
if ($^V and $^V lt v5.6.0) {
my $pkg = caller;
*{"$pkg\::our"} = sub {@_[0..$#_]};
}
else {
goto &strict::import;
}
}
1;
and then use strictitude rather than strict.
The idea is simple, if the Perl version is too low, export a useless our function to prevent errors and turn off strict checks. For recent Perls do what strict does so you can catch undeclared variables. | [reply] [d/l] |
|
if ($] and $] < 5.006)
It works under 5.5 and under 5.6/5.8 as well. I know I've got to be one of the few monks around here that still lives in 5.005_03.
------------
:Wq
Not an editor command: Wq
| [reply] [d/l] [select] |
|
You should send in a documentation patch for perlvar then, because I pulled this line from there:
This can be used to determine whether the Perl interpreter exe-
cuting a script is in the right range of versions. (Mnemonic:
use ^V for Version Control.) Example:
warn "No \"our\" declarations!\n" if $^V and $^V lt v5.6.0;
| [reply] [d/l] |
|
|
I can sympathise completely - the shop I work for is still down there in Perl 5.005 .. with "no plans to upgrade in the forseeable future" in case it breaks things.
| [reply] |
|
|
Ok, almost there
The project is a constant work in progress, most of the our definitions could be changed to my, but will need our in the future. All 'our's that need to be global right now have a corrosponding VARS placement so that shouldn't cause any problem.
I'm not using strict at this stage in this particular script. That code looks almost like what I need, but without referencing my on any our calls.
The main errors I'm getting is something like this:-
"our %hash;" - error illegal modulas of 0. Because our isn't defined it's treating % as a modulas.
I'm sure the solution is quite simple, I just don't quite know how to do it.
The host has got back to me saying the server is part of a nest and they don't want to upgrade all of them, but I'm still trying.
Thanks in advance.
| [reply] |
|
|
I'm sure something like this is possible:-
*{"&our"} = \&{my};
I know it's wrong and doesn't work. But I'm sure one of you wise monks know how to do it.
| [reply] |
Re: Problems with 'our' definition with perl 5.00503
by Tanktalus (Canon) on Jun 30, 2005 at 00:48 UTC
|
While it sounds like you want some sort of Filter::Simple that does this conversion, that's just a bad idea to me. Better to have a Makefile.PL or Build.PL which calls a conversion script that converts during "make" or "Build" and then installs.
But I'd stick to my guns on the perl 5.8 upgrade - 5.005 is really old and not as well supported.
| [reply] |