use “perl -w”!

I thought "use strict" is enough and didn't try to run an application with the "-w" flag. (Don't blame me, it was under Windows.) As result, I played ping-pong with an user trying to identify an error instead of preventing the error.

Here is a minimal test case:

use strict;

&test(3);
&test(4);
&test(5);

sub test {
  my $param = shift;
  my $local;
  sub print_local {
    print "local = $local\n";
  }
  $local = $param;
  &print_local;
}

I expected to get:

local = 3
local = 4
local = 5

Actually I got:

local = 3
local = 3
local = 3

It's very counter-intuitive. If I used "-w", I'd get the warning:

Variable "$local" will not stay shared at closure.pl line 11.
Categories:

Updated: