I would avoid using $_ as a temporary variable, even when localised. Not because it will break your code as it is but because the next coder (or even you some time later) who comes along won't be expecting it and could get bitten.

If the var is so transient that $_ is an OK name for it then, as you say, "my $x;" is shorter to type than "local $_;" :) I would still use a more meaningful name though eg. $temp_foo_counter or $partial_interest_calc etc. If it is distinctly named it is much less likely to cause problems later on.

Update:I read the original node as suggesting using $_ as a generic temporary variable and not necessarily to take advantage of Perl's built in use of $_ as the default target. I have used $_ as converter described and didn't mean to suggest you shouldn't use it for that, though I still advocate taking care :)

--
Life is a tale told by an idiot -- full of sound and fury, signifying nothing. William Shakespeare, Macbeth


In reply to Re: Using $_ as a temp var, especially in functions by greenFox
in thread Using $_ as a temp var, especially in functions by BUU

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.