I have a Perl script that needs to run on both Perl 5 and Perl 6 environments. If using Perl6 I need to use "perl6::Form" while on Perl5 I need to use "Format".
This code works on both versions or perl without error:
BEGIN {
if( $] ge 6){
require Perl6::Form;
Perl6::Form::->import();
}
}
But I do not know how to "separate" the Perl6 code when running on Perl5.
if( $] ge 6){ # Perl6
print form
...
...
} else { # perl5
format STDOUT =
...
...
}
This doesn't work cleanly as I get errors on Perl5:
Unquoted string "form" may clash with future reserved word at /usr/bin/script.pl line 628.
Name "main::form" used only once: possible typo at /usr/bin/script.pl line 641.
I've briefly looked at Text::CPP
, but I don't want to have a dependency on a compiler being installed. Any suggestions would be appreciated.
If using Perl6 I need to use "perl6::Form"
perl6::Form doesn't exist.
Perl6::Form is a Perl5 module that provides functionality similar to Perl6's form
.
A Perl6 module would have no use for Perl6::Form even it could run it since it's part of the language.
But I do not know how to "separate" the Perl6 code when running on Perl5.
Perl6 is not a version of Perl5. Perl5 and Perl6 are completely different languages. (Perl5's latest version is currently 18.1) I don't see how you can think you can have a program executed by both.
The best way to separate a Perl5 program and a Perl6 program is to put them in different files. If you have a need to place them in the same file, you'll need to state that need for us to help you find an appropriate solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With