Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Cross-developing in 5.005 and 5.6 (code)

by deprecated (Priest)
on May 15, 2001 at 19:21 UTC ( [id://80559]=perlquestion: print w/replies, xml ) Need Help??

deprecated has asked for the wisdom of the Perl Monks concerning the following question:

BEGIN { eval{ use warnings; use strict; use Carp; use CGI::Carp qw{ fatalsToBrowser }; use CGI qw{ :standard :form }; } }
I am developing a perl application in 5.6.1 for a system that is 5.005. However, we do have a 5.6 system, and I am hoping that we will have several more relatively soon. What I'm trying to accomplish here is throw the pragmas and modules in the eval block so that perl 5.5 wont whine about them. However, I am still getting a fatal error about not being able to find warnings.pm. How can I get around this?

thanks
brother dep.

--
Laziness, Impatience, Hubris, and Generosity.

Replies are listed 'Best First'.
Re (tilly) 1: Cross-developing in 5.005 and 5.6 (code)
by tilly (Archbishop) on May 15, 2001 at 19:39 UTC
    Given that Perl promises backwards but not forwards compatibility, it is best to develop in Perl 5.005 if you want it to run on both.

    But that detail aside, you will find your answer in the documentation for eval. Which is where you should have looked first.

    OTOH when you are done that you will find yourself reaching for answers to several other questions. For instance why is strict not being picked up? Also why is 5.005 going to fail to pick most of those modules?

    A far, far better solution is to create useless fallback versions of 5.6 specific modules. Then just use away with no trickery.

Re: Cross-developing in 5.005 and 5.6 (code)
by mr.nick (Chaplain) on May 15, 2001 at 19:27 UTC
    I found that by wrapping the individual use's in the eval inside of quotes worked:
    BEGIN { eval "use warnings"; eval "use strict"; eval "use Carp"; }
    (this is on a 5.005_03 system).
Re: Cross-developing in 5.005 and 5.6 (code)
by MrNobo1024 (Hermit) on May 15, 2001 at 19:27 UTC
    eval { block } can still have compile time errors. If you want to trap those too, you need to use eval "string" instead.
(dkubb) Re: (2) Cross-developing in 5.005 and 5.6 (code)
by dkubb (Deacon) on May 16, 2001 at 11:13 UTC

    Remember that strict is only going to be honored in the scope it was declared in.

    In this snippet of code, strict isn't making any difference to the code outside of the BEGIN block. Try placing a non-lexically scoped variable after the BEGIN block, and watch as perl let's it pass without complaining.

Re: Cross-developing in 5.005 and 5.6 (code)
by Anonymous Monk on May 15, 2001 at 19:26 UTC
    Do NOT use warnings. REQUIRE them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://80559]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-20 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found