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

On one machine (Scientific Linux 6.9, Perl v5.10.1) I get plenty of warnings such as "Use of uninitialized value $xyz..." but the very same script gives me no warnings on another machine (Ubuntu 16.04, Perl v5.22.1). I copied it over with scp. Both copies of the same script start with:
use strict; use warnings;
Does anyone have any idea what might be causing this?

Replies are listed 'Best First'.
Re: Warnings not working on one machine
by Eily (Monsignor) on Jan 25, 2018 at 15:15 UTC

    It can be pretty much anything. Maybe the two machines also have different versions for the same module, and the interface is different. Maybe the value that is present in one version comes from some input data, like files on the system, the environnement, the name of the user... Maybe the script relies on some undefined behaviour which was documented as unreliable in the doc, and turned out not to be reliable.

    It's impossible to know if you don't give us more info. Some of the code where the warning happens would be a minimum.

Re: Warnings not working on one machine
by ikegami (Patriarch) on Jan 26, 2018 at 05:09 UTC

    What output do you get from the following command?

    perl -e'use warnings; print undef; print "done\n";'
      Hi folks, thanks for your replies. I get the same results for both machines:
      me@BothMachines: perl -e'use warnings; print undef; print "done\n";' Use of uninitialized value in print at -e line 1. done me@BothMachines: cat test.pl #!/usr/bin/perl use strict; use warnings; print undef; print "done\n"; me@BothMachines: ./test.pl Use of uninitialized value in print at ./test.pl line 4. done
      After playing around a bit more I realised that the location in the code where this is happening is in another perl file which I include by require. The included file does not have use statements. Are the use strict; and use warning; only applied to the current file, and not those included by require?

      However, this still does not explain why it shows the warnings on one machine and not the other. I can't post work-code here, but I will construct an simple example that is equivalent and post here.
        So, here are some examples of code producing different results on both machines. test2.pl runs alone by itself, test3.pl does the exact same tasks but uses the test3_utils.pl file. In both cases, warnings and variable contents differ per machine.
        cat test2.pl #!/usr/bin/perl use strict; use warnings; use Cwd; use File::Basename; use List::Util qw(min max); use Math::Round; use Sort::Key::Natural qw(natsort); use Storable 'dclone'; use Sys::Hostname; use Term::ANSIColor; print "decimal places: ".length(("1" =~ /\.(\d*)/)[0])."\n"; print "decimal places: ".length(("0.123" =~ /\.(\d*)/)[0])."\n"; my $line = "apple="; my $second_part = (split(/=/, $line))[1]; my $second_part_components_count = (length $second_part > 0 ? scalar ( +split(/;/, $second_part)) : 0); print "done\n"; cat test3.pl #!/usr/bin/perl use strict; use warnings; use Cwd; use File::Basename; use List::Util qw(min max); use Math::Round; use Sort::Key::Natural qw(natsort); use Storable 'dclone'; use Sys::Hostname; use Term::ANSIColor; require "test3_utils.pl"; do_foo(); do_bar(); print "done\n"; cat test3_utils.pl #!/usr/bin/perl sub do_foo { print "decimal places: ".length(("1" =~ /\.(\d*)/)[0])."\n"; print "decimal places: ".length(("0.123" =~ /\.(\d*)/)[0])."\n"; } sub do_bar { my $line = "apple="; my $second_part = (split(/=/, $line))[1]; my $second_part_components_count = (length $second_part > 0 ? scal +ar (split(/;/, $second_part)) : 0); } 1; # need to end with a true value

        The scripts are copied to the second computer (SciLnx) where they produce different results:

        me@UbuntuMachine: ./test2.pl Use of uninitialized value in concatenation (.) or string at ./test2.p +l line 14. decimal places: decimal places: 3 Use of uninitialized value $second_part in numeric gt (>) at ./test2.p +l line 19. done me@UbuntuMachine: ./test3.pl decimal places: decimal places: 3 done me@SciLnxMachine: ./test2.pl Use of implicit split to @_ is deprecated at ./test2.pl line 19. Use of uninitialized value in length at ./test2.pl line 14. decimal places: 0 decimal places: 3 Use of uninitialized value $second_part in length at ./test2.pl line 1 +9. done me@SciLnxMachine: ./test3.pl decimal places: 0 decimal places: 3 done
        I would expect the same results and the same warnings on both machines. To my surprise, neither is the case. The SciLnx is returning 0 where the Ubuntu machine is returning nothing.

        The software in question is distributed to partners, it is important that it does what we expect. Is there any way to investigate what is causing this behavioural difference?