You would usually say
{ local $#; ... do some stuff }
to have e.g. $# restored at the end of a block.

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.


In reply to Re: restoring special variable defaults by ysth
in thread restoring special variable defaults by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.