Make a Perl script run on both Perl 5 and 6

I have a Perl script that should work on both Perl 5 and Perl 6. If I use Perl6, I need to use “perl6 :: Form”, and on Perl5 I need to use “Format”.

This code works on both versions or perl without errors:

BEGIN { if( $] ge 6){ require Perl6::Form; Perl6::Form::->import(); } } 

But I do not know how to "separate" the Perl6 code when working on Perl5.

 if( $] ge 6){ # Perl6 print form ... ... } else { # perl5 format STDOUT = ... ... } 

This does not work cleanly since I get errors in 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 looked briefly at Text::CPP , but I do not want to have a dependency on the installed compiler. We appreciate any suggestions.

+4
source share
1 answer

When using Perl6 I need to use "perl6 :: Form"

perl6 :: Form does not exist.

Perl6 :: Form is a Perl5 module that provides functionality similar to Perl6 form .

The Perl6 module will not be used for Perl6 :: Form, even if it can run it from that part of the language.

But I do not know how to "separate" the Perl6 code when working on Perl5.

Perl6 is not a version of Perl5. Perl5 and Perl6 are completely different languages. (The latest version of Perl5 is currently 18.1). I do not see how you can think that 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 need to place them in one file, you need to indicate that we need to help you find the right solution.

+12
source

Source: https://habr.com/ru/post/1497054/


All Articles