I was able to run the following code on my local machine where I have a power of sudo"
#!/usr/bin/env perl
package Cat
{
use Moose;
has 'name', is => 'ro', isa => 'Str';
}
my $test_obj = Cat->new(name => "kitty");
print $test_obj->name()."\n";
result :
$perl Cat.pl
kitty
But when I ran the exact same code in other machines where I do not have sudo, I get the following error:
syntax error at Cat.pl line 5, near "{
"
Execution of Cat.pl aborted due to compilation errors.
Why does this happen?
I installed the Module using cpanm on all of my three machines, one with sudo and the two without sudo(I installed them locally). The versions of perl are :
machine 1(worked, has sudo) : (v5.14.2) built for cygwin-thread-multi-64int
machine 2(did not work, no sudo previlage) : perl, v5.10.1 (*) built for x86_64-linux-thread-multi
machine 3(did not work, no sudo previlage) : v5.10.0 built for x86_64-linux-thread-multi
So it seems like it has to do with shared library or something, but I cannot figure out exactly why it doesn't work on the two machines. Is this a known issue?
The package { ... }
syntax you're trying to use was added in perl 5.14.0 (released in May 2011).
If you want to run on perl 5.12 and older, change your code to look like:
{
package Cat;
use Moose;
has 'name' => (...);
# etc.
}
my $test_obj = Cat->new(...);
# etc.
The package
declaration won't leak outside of the braces, so the code at the bottom will be running in package main
, and my
or our
variables will stay inside of the block as well.