What is wrong with:
package Our;
require strict; # Must be sure it has been loaded
sub import {
if ($] < 5.006) {
my $pkg = caller();
*{"$pkg\::our"} = \*our;
@_ = qw(strict vars);
goto &strict::unimport;
}
}
sub our {
}
1;
__END__
=head1 NAME
Our - pragma to gracefully degrade 'our' on older Perl's.
=head1 SYNOPSIS
use strict;
use Our; # Must appear after strict
our($foo);
=head1 DESCRIPTION
On older versions of Perl this undoes strict vars, and imports an
our function. This allows modules to be developed on newer Perl's
using 'our' yet still run on older installations.
=head1 BUGS
This provides backwards but not forwards compatibility. Caveat
developer.
Try the following sample script:
use strict;
use Our;
our ($foo);
$foo = "hello\n";
print $foo;
OK, so you have to put the Our after the strict. And to get the benefit from strict you need to be doing your development on a recent version of Perl. But this lets you get all of the development benefits of our while still retaining backwards compatibility.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|