This is not about "fusion", it's about confusion.

I have absolutely no clue about what exactly you are trying to achieve, but maybe it helps you to point out that "my"-variables are lexically scoped and that means that they are only visible within the nearest "{"-block.

And if you stack my-declarations you simply shadow previous ones.

Consider this:

use strict; my $whatever = "outer"; if (1) { my $whatever = "inner"; print "$whatever\n"; } print "$whatever\n";
Here you have a lexically-scoped variable in the outer scope and the same one in the scope introduced by if.

Within the if-block $whatever is changed to "inner", and that is what is printed from the print there, but once you leave this scope you refer to the outer definition and so the outer print prints "outer" (what else?).

In your case you have "my $test" in the outer scope.

Then you introduce a new scope with "if" and declare a new variable with "my $test" and set that to "GOOD". Here you shadow the already introduced variable. Later (in another if-scope) you introduce yet another variable (again shadowing the outer one) and that of course knows nothing about the assignment you did in another scope.

Short story:

You are dealing with three different variables here: The outer $test, the $test in the first if and the $test in the second if.

This probably was confusing - sorry for that but I am a bit drunk...


In reply to Re: local & global function by morgon
in thread local & global function by dideod.yang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.