b4swine has asked for the wisdom of the Perl Monks concerning the following question:
I have very strange (quantum-like: looking at a variable causes it to exist with the right value!) behavior, which I am sure must be documented somewhere deep in the perl documentation.
I can't replicate it in any small program, so I will describe the behavior here.
Update: see my reply to myself, where a small program to replicate this behavior is shown
A package I have reads:
gives me: Use of uninitialized value in concatenation (.) or string at (eval 40) line 1. but if I uncomment the print line, everything works fine, and 'this string' prints out with no errors at all!... my $var ... sub initialize { ... $var = 'this string'; ... } sub mysub { # print STDERR "var = $var"; print STDERR eval("...$var..."); } BEGIN { initialize() }
It is a large, spaghetti of a program, but I have verfied that deleting the one comment character produces this result.
I know that looking at a variable can cause it to get defined, but how can a simple print cause an unitialized variable to get defined with the right value?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: quantum behavior in perl? (cheap closures)
by tye (Sage) on Aug 18, 2007 at 06:13 UTC | |
by b4swine (Pilgrim) on Aug 18, 2007 at 06:22 UTC | |
|
Re: quantum behavior in perl?
by chromatic (Archbishop) on Aug 18, 2007 at 06:07 UTC | |
by tye (Sage) on Aug 18, 2007 at 06:18 UTC | |
by chromatic (Archbishop) on Aug 18, 2007 at 17:36 UTC | |
by tye (Sage) on Aug 18, 2007 at 19:05 UTC | |
|
Re: quantum behavior in perl?
by ikegami (Patriarch) on Aug 18, 2007 at 06:16 UTC | |
by tye (Sage) on Aug 18, 2007 at 06:29 UTC | |
|
Re: quantum behavior in perl?
by bobf (Monsignor) on Aug 18, 2007 at 06:35 UTC | |
by b4swine (Pilgrim) on Aug 18, 2007 at 06:43 UTC | |
|
Re: quantum behavior in perl?
by b4swine (Pilgrim) on Aug 18, 2007 at 11:15 UTC | |
by mr_mischief (Monsignor) on Aug 20, 2007 at 03:08 UTC |