Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
What would you expect it to print?my $string = 'foo'; my $variablename = 'string'; my $temp = ${$variablename}; print $temp, $/;
It prints only $/, because $temp gets nothing from the assignment.
However this:
works as expected.$string = 'foo'; my $variablename = 'string'; my $temp = ${$variablename}; print $temp, $/;
I can't run the first one under strict, because it won't allow the scalar reference.
But when I run it with warnings, the only warning I get is about the uninitialised value in the concatenation.
What am I missing about scope here?
P.S. I really do know why coding this way is a Bad Idea. I was in a big hurry!
($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scope Puzzle
by merlyn (Sage) on Feb 17, 2006 at 01:27 UTC | |
|
Re: Scope Puzzle
by GrandFather (Saint) on Feb 17, 2006 at 01:44 UTC | |
|
Re: Scope Puzzle
by ikegami (Patriarch) on Feb 17, 2006 at 05:41 UTC | |
|
Re: Scope Puzzle
by chromatic (Archbishop) on Feb 17, 2006 at 06:36 UTC | |
by Anonymous Monk on Feb 17, 2006 at 08:12 UTC |