in reply to restoring special variable defaults
to have e.g. $# restored at the end of a block.{ local $#; ... do some stuff }
To force something to stringize as a number, first convert it with the 0+ operator and then use it in a string context:$x = "0."; $x = 0+ $x; print $x; Just kidding, there is no 0+ operator; but simply adding 0 as above will produce something with a numeric value and no string value; then using it in string context will cause the numeric value to be stringized, invoking $# (unless the newish preserve-integers-where possible logic kicks in).
By the way, $# is deprecated; use printf/sprintf directly instead; that will save you having to do the conversion: $x = "0."; printf "%.15e", $x and will avoid the aforementioned problem with perl bypassing floating point.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: restoring special variable defaults
by Anonymous Monk on Feb 09, 2004 at 17:09 UTC | |
by ysth (Canon) on Feb 09, 2004 at 17:13 UTC |