zatlas1 has asked for the wisdom of the Perl Monks concerning the following question:

I have this script:
perl -e ' use strict; use warnings; use Data::Dumper; use lib "\/xxx\/common\/bin"; use DMDCombo2; my $x = DMDCombo2->new; print Dumper $x; my $y = $x->export_envvars; print $y; '
my old Solaris and new Linux share the /xxx mount
when run on Solaris with Perl 5.10.0 (I kid you not), I get the expected results
When run on Linux with Perl 5.28, I get
$VAR1 = undef;
Can't call method "export_envvars" on an undefined value at -e line 9.
I cannot share the 'new' code but it ends with:
bless $self,$class; return $self; }
What do I do wrong in 5.28 that 5.10 used to tolerate?
Thank you
ZA

Replies are listed 'Best First'.
Re: Difference between old and new
by Corion (Patriarch) on Nov 13, 2023 at 18:57 UTC

    The only thing we can do to help is help you reduce your code so you can show it to us.

    Somehow the code in DMDCombo2 returns undef. We cannot know why unless you reduce it to something you can show us.

      This was a great help. I've found the issue!
      It is a complex proprietary module, and yes, it does return explicit undef under some circumstances
      Thank you
      ZA
Re: Difference between old and new
by hv (Prior) on Nov 13, 2023 at 18:47 UTC

    Sorry, there appears to be insufficient information.

    The shared /xxx mount does not appear to be relevant: you're successfully loading the DMDCombo2 module, or you would get an error from the new() call before you reached the print. It is also not reaching the two lines from the new method that you show: if $self were undef at that point, you would get an error like "Can't bless non-reference value". So something is going wrong within that new() method, causing it to return an undef before it reaches the final two lines.

    If you cannot show its code, nor a cut-down or sanitised version of it that exhibits the same error, I suggest the following steps: 1) copy the module to somewhere local on the linux box, modify the use lib statement appropriately, and satisfy yourself that the shared mountpoint is not the cause of the issue; 2) add diagnostics in the new() method in this copy to see which lines it is executing and understand where it is returning.

    It will almost certainly be hitting an explicit return statement in that new() method, but diagnostics should easily make it clear where it is reaching; if the answer is not obvious at that point, you will at least have more information to share with us.

Re: Difference between old and new
by InfiniteSilence (Curate) on Nov 14, 2023 at 01:21 UTC

    Get out of the habit of evaluating your code in the manner shown.

    If you must, write a script that does what you want and run it against different Perl versions. I prefer to use Test::More and run that periodically to catch errors that will appear over time as dependencies change. I hear h2xs is deprecated but I will use it for instructional purposes here:

    cd /tmp h2xs -AXn junk cd ./junk cd t cat junk.t

    Above produces boilerplate test code you can produce literally in seconds.

    use strict; use warnings; use Test::More tests => 2; BEGIN { use_ok('DMCombo2');}; ...

    Change things for your environment. Six months down the road you will be thanking yourself for investing the time to learn this stuff.

    Celebrate Intellectual Diversity