I frankly think the perl tag should be banned from Stack Overflow, or be an alias for perl5.
( On other Stack Exchange sites it may make sense to still allow it separately )
Tagging Perl 4, Perl 5 and Perl 6 with the same tag is like tagging C, C++ and C# with the same tag. They are that different.
While it is theoretically possible to write code that works the same in both Perl 5 and Perl 6, it is also possible to write code that works in both, but works completely differently.
(Similar to making code work in many different languages at the same time)
Here is just a quick example
print "Hello from Perl ", 5 + !!"0", "\n";
In Perl 5:
Hello from Perl 5
In Perl 6:
Hello from Perl 6
If you wanted to print more about the version you are using:
#`{ // start of inline comment in Perl 6
#// Perl 5 in a Perl 6 comment
use 5.010;
say "Perl $^V"; # stringifies $^V object
' // start of string in Perl 5
}; # // end of Perl 6 inline comment
#// Perl 6 in a Perl 5 string
say $*PERL; # calls .gist on $*PERL object
say $*PERL.compiler;
#// ' # // end of string in Perl 5
(I used the Javascript highlighter to get some color without choosing Perl 5 highlighting over Perl 6, that's why there are //
for every comment)
In Perl 5.20.1
Perl v5.20.1
In Perl 6
Perl 6 (6.c)
rakudo (2015.12.220.gcf.7706.f)
(There are more complex examples that don't use Perl 6 inline comments)
Those are just the simple examples, the following is valid Perl 6, but invalid in Perl 5.
Not to mention that it would be much more work to even get something that remotely works similarly in Perl 5.
(Probably using an overloaded class for the string argument, or a module that allows you to hack into the parser.)
{
# make 5 + " 6" work the same as it does in Python,
# but only for the enclosing scope
multi sub infix:<+> ( $l, Str $r ) { $l ~ $r }
say (5 + " 6") eq "5 6"; # True
}
# back to the Perl way of working
say (5 + " 6") eq "11"; # True
Objects are also different
Plain Perl 5: (no modules)
use 5.020;
package MyClass {
my @methods;
BEGIN {
# Set this in a BEGIN block
# so it is available in the other BEGIN block.
@methods = qw'a b';
}
sub new {
my ($self,%values) = @_;
my $class = ref $self || $self;
# requires 5.20+ I believe for %hash{@keys}
bless {%values{@methods}}, $class;
}
BEGIN {
# This is advanced code
# that shouldn't be done by novices.
# It would be safer with Package::Stash
for my $method (@methods) {
no strict 'refs';
*{"MyClass::$method"} =
sub {
my ($self,$new_value) = @_;
if( @_ > 1 ){
$self->{$method} = $new_value;
} else {
$self->{$method}
}
}
}
}
}
my $obj = MyClass->new(a=>1,b=>'Hello');
say $obj->a; # 1
$obj->a(5);
say $obj->a; # 5
Perl 6:
class MyClass {
has Int $.a is rw;
has Str $.b is rw;
}
my $obj = MyClass.new: :a(1), :b<Hello>;
# MyClass.new: a => 1, b => 'Hello'; would have also worked
say $obj.a; # 1
$obj.a = 5;
say $obj.a; # 5
There are modules that you can and should use to get very close to the default in Perl 6, which I would absolutely recommend using if you don't have a good reason not to.
I don't consider them not coming with perl
that good of a reason.
The reason I think it might be okay for perl be an alias to perl5 is that Perl 5 is almost completely backwards compatible to the original version of Perl released in 1987, and is what most people really mean when they say Perl.
( Most of the things that were removed or changed you shouldn't really use, or not that well designed to start with. )
[perl]
[perl5]
[perl6]
[perl5.8]
[perl5.10]
[perldoc]
[perl-module]
( or just[perl*]
and look at stackoverflow.com/questions/tagged/… unfortunately they are separate features, and neither are well supported)