Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found