Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^5: RFC: Tutorial: use strict; now what!?

by tangent (Priest)
on Feb 17, 2012 at 18:13 UTC ( #954577=note: print w/replies, xml ) Need Help??

in reply to Re^4: RFC: Tutorial: use strict; now what!?
in thread RFC: Tutorial: use strict; now what!?

Thanks for taking the time to explain Xiong, and I get the connection now, even though I had to read through everything a few times. Being an obedient student, I always use warnings as well as strict, and note that I get a warning if I try to print $hash{pensionbalance} and also if I say something like:
my $debts = 100; my $money_left = $debts - $hash{pensionbalance}; # Use of uninitialized value in subtraction (-)
Am I safe to assume then that use warnings will always keep me safe?

Replies are listed 'Best First'.
Re^6: RFC: Tutorial: use strict; now what!?
by runrig (Abbot) on Feb 17, 2012 at 18:57 UTC
    In this case it will. Or if you set all warnings to be fatal then you're extra "safe". Depending on how you use the value though, you may or may not get a warning. If you just use it as a boolean you do not get a warning:
    if ($hash{pensionbalance}) { print "Got a pension balance!\n"; }
      I kinda knew there would be something. And "if ($hash{pensionbalance})" is exactly the sort of thing I would put in to avoid all those "uninitialized value" errors. The plot thickens... I could change those conditions to:
      if (exists $hash{pensionbalance}) { print "It's there, there's just nothing in it\n" }
        Being an obedient student, I always use warnings as well as strict...
        The plot thickens...

        Sorry, tangent; neither strictures nor warnings are always appropriate. That's why they can be turned off -- in fact, they're off by default. Much power is hidden away by each. Usually you don't want, or need, to do such stuff. Sometimes you do.

        Also, no tool can guarantee that your code is bug-free or even typo-free. Some tools help to protect against some common mistakes but in the end, it's up to you. The most important abilities required to write less-buggy programs are (obliquely to Wall's dicta) humility, intellectual honesty, clean and consistent style, flexible focus, and raw experience.

        I would not recommend that you check every hash key for existence before each use. But if you want to do something like this, you can try Hash::Util or (if you tend to work with $hashrefs rather than actual %hashes) Data::Lock. Please note that these are not equivalent tools.

        Please don't take away from any comment here, especially from any comment of mine, that you must always or must never do anything. Software should be judged (in this order) by: (1) how well it works for the user, (2) how well it serves the needs of those who incorporate it as a component of other projects, and (3) how well it can be maintained, extended, and upgraded in future. Not on the list: impressing CS profs and didactic engineers busy evading their own work while prescribing your style.

        I'm not the guy you kill, I'm the guy you buy. —Michael Clayton

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954577]
[Corion]: Meh. I need to find myself a better "programming" feed than r/programming (which is just HackerNews reposts and advertisements, very little code). Maybe I should select a list of links that I liked on r/programming and then google for ...
[Corion]: ... an aggregator site that also listed (ideally) all of these links once. And maybe also have an exclude list to blacklist some of the most spammy links that the site may have never mentioned at all
[marto]: I gave up reading HN at all, and feel much better for it :P
[Corion]: Now, how to best automate that Google search ... :-)
[Corion]: marto: Yeah, I'm also short of not reading it at all. I already stopped reading it in the morning because it gave me a foul mood.
[Corion]: The good posts on HN are the non-computing posts. Most of the other stuff is maybe relevant to you if you are 20 and live in Silicon Valley...
[Corion]: Two attributes that don't describe me.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-07-24 13:22 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.