将对象作为具有不同Perl版本的输入参数传递

问题描述 投票:0回答:1

传递对象]时遇到问题]作为输入参数,其perl版本从perl5.6.pl到perl5.24.pl(无法从函数“ $ from_5.24”获取返回值)。在有问题的代码。下面提供使用Windows平台,如何解决此问题。

SharedBetweenPerls.pm:-

package SharedBetweenPerls;
use warnings;
use strict;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT_OK = qw(getVal);

sub new {
   my $self = {
      roleId => undef,
      username => undef,
   };
   bless $self, 'SharedBetweenPerls';
   return $self;
}

sub getVal{
  my ($self) = @_;
  return $self->{'roleId'};
}
1;

v5.24.pl:-

use warnings;
use strict;
use v5.24;
use lib '.';
my ($self) = @_;
print $self->{'roleId'}; **#Not working..**

v5.6.pl:-

use warnings;
use strict;
use lib '.'; 
use SharedBetweenPerls;

my $obj =  new SharedBetweenPerls();
$obj->{'roleId'} = '10000';
$obj->{'username'} = 'test123';

my $roleId = $obj->getVal();
print "Value : $roleId \n"; **#working fine**

my $from_5.24 = qx(path-to-perl-5.24 program_for_5.24.pl "$obj"); 
print "Return from function: $from_5.24"; **#Not Working**

在将对象作为输入参数使用perl5.6.pl至perl5.24.pl不同的perl版本时遇到问题(无法从函数“ $ from_5.24”获取返回值)。在下面提供...

perl object arguments version perl-module
1个回答
1
投票

这是previous question中出现的问题的更一般的情况,其中现在要在程序之间传递对象。这种变化带来了很大的不同。

© www.soinside.com 2019 - 2024. All rights reserved.