in reply to Re: variable has value but then become empty
in thread variable has value but then become empty

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: variable has value but then become empty
by stevieb (Canon) on Sep 09, 2015 at 14:33 UTC

    Please, please, please put your code in <code></code> tags as I said above. Many Monks won't even bother to look at a question that isn't formatted, especially when it's already been pointed out previously.

    Have you tried printing out the variable after each modification to itself to see what the value is?

    $public_key_type = scalar <DATA> for 1; print ">$public_key_type<\n"; $public_key_type =~ s/^\s+//; print ">$public_key_type<\n"; $public_key_type =~ s/\s+$//; print ">$public_key_type<\n"; $public_key_type =~ s/\R//g; print ">$public_key_type<\n";
      Yes tried that. I can print the variable to the screen as long as I am in the same code block. Once I leave the code block the variable becomes empty.

        If you can print the variable immediately before you leave the block and see the value you expect, then print the variable immediately after you leave the block and see a different value, that strongly suggests a "masking variable" situation like the ones discussed by 1nickt here and sundialsvc4 here.

        IOW: You have a lexical variable defined within a statement block (a lexical scope) that has the same name as a variable defined outside the block. You assign to and print the variable inside the statement block, but that variable goes away when execution leaves the block, at which time you are left with the outside variable and whatever value it has. I can only suggest you carefully examine your code.


        Give a man a fish:  <%-{-{-{-<