Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: <STDIN> not initializing $_

by wade (Pilgrim)
on Apr 30, 2008 at 23:22 UTC ( #683812=note: print w/ replies, xml ) Need Help??


in reply to <STDIN> not initializing $_

Yeah, and since $_ can get silently overwritten (especially as you add code and forget that you were counting on $_) I really hate to use it. Instead, I assign everything to my own variables:

use strict; use warnings; while (1) { my $foo = <STDIN>; $foo =~ m/./ and print "success.\n"; # ... (more code) ... }

I'd also tend not to use a while(1) loop but that's a whole other Oprah.

--
Wade


Comment on Re: <STDIN> not initializing $_
Select or Download Code
Re^2: <STDIN> not initializing $_
by oko1 (Deacon) on May 01, 2008 at 00:30 UTC
    > Yeah, and since $_ can get silently overwritten [...]
    

    Just about as silently as every other variable in Perl. No matter what your own preferences may be, '$_' is an important and integral part of Perl - and there's no reason to give misleading advice to someone who is trying to learn about it.

    > [...] I really hate to use it.
    

    Say 'goodbye' to grep and map, then. In fact, bid 'good night' to half the functionality of most Perl functions.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells
    
      I'm just saying that I like to assign values to variables explicitly when possible. I think it's clearer and a little less error-prone but that's just me.
      --
      Wade

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://683812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2015-07-06 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (81 votes), past polls