in reply to Global variable unexpectedly modified when passed by reference
For those of you who might be schooled in other programming languages, it might be useful to you for me to point out that Perl really doesn’t have the notion of “[passing parameters by] reference.” Instead, it has a generally-applicable notion of: references.
“A reference” is, first of all, sort-of “a data type.” In other words, “any variable’s value” could be (say ...) integer, string, floating-point, file-handle, or ... “reference.” Every “thing” in the Perl world has a “reference count” associated with it, and the Perl runtime system somehow keeps everything straight, so that nothing gets de-allocated too soon.
Nevertheless, this creates a situation that catches many programmers who are accustomed to “strongly-typed,” “compiler-oriented” language systems somewhat off-guard: it’s all very dynamic. When a variable contains “a reference,” anything that you do to it is automatically and transparently conveyed to act upon its “target.” But, that very same variable could at some time cease to contain a “reference” value and, instead, contain an ordinary scalar value, in which case it would behave altogether differently than before. The runtime behavior of the variable is not bound-to nor determined-by its compile-time (syntactic ...) characteristics. Instead, that behavior is determined by its (perhaps, very immediate) history and provenance.
“With great power comes great responsibility ...”
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Global variable unexpectedly modified when passed by reference
by Anonymous Monk on Dec 08, 2014 at 21:37 UTC | |
by Anonymous Monk on Dec 10, 2014 at 01:47 UTC | |
| |
|
Re^2: Global variable unexpectedly modified when passed by reference
by Anonymous Monk on Dec 09, 2014 at 01:21 UTC | |
|
Re^2: Global variable unexpectedly modified when passed by reference
by marto (Cardinal) on Dec 09, 2014 at 10:50 UTC | |
|
Re^2: Global variable unexpectedly modified when passed by reference
by ikegami (Patriarch) on Dec 10, 2014 at 07:13 UTC | |
|
Re^2: Global variable unexpectedly modified when passed by reference
by Anonymous Monk on Dec 10, 2014 at 01:46 UTC |