in reply to "my" declaration problem

> Now,can any monk explain me just what happen here?

because ...

> without strict nor warnings ^_^

Or differently phrased:

Repeated declarations of the same variable in the same scope make no sense.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: "my" declaration problem
by Anonymous Monk on Apr 25, 2017 at 18:57 UTC

    Repeated declarations of the same variable in the same scope make no sense.
    In bad style and obfuscated, sure, but is it nonsensical? Redeclaration and reassignment are not the same when destructors or side-effects are involved. I can imagine this kind of situation arising with "templated" code where sections are copy-paste or somesuch. Job security FTW!

      OK ... Please provide an example where the code is not broken.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        The following code might have been autogenerated. It's not even really confusing and it works exactly as advertised:

        use Guard; use File::Temp 'tempfile'; sub frobnicate { my ($fh,$name) = tempfile(); print {$fh} "Hello"; close $fh; my $atexit = guard { print "Removing '$name'"; unlink $name; }; my ($fh,$name) = tempfile(); print {$fh} "World"; close $fh; my $atexit = guard { print "Removing '$name'"; unlink $name; }; } print "Frobnicating"; frobnicate(); print "Frobnicating done, and cleaned up"; __END__ Frobnicating Removing 'C:\Users\Corion\AppData\Local\Temp\JPUN_wEVOo' Removing 'C:\Users\Corion\AppData\Local\Temp\eUuaGV_5sj' Frobnicating done, and cleaned up

        Of course, there is no way to get at the first instances of $fh, $name and $atexit.

        And if I were autogenerating that code, why would I bother with naming the variables $name1, $name2 etc. when they are just for later customization anyway?