my $someone; will create the variable so that you can put a string, number, reference, or some other perlish piece of data into $someone. In your snippet of code, however, you do not place a value into that scalar variable. As well, the '-w' on the first line of the script and the 'use warnings' line do more or less the same thing, so you can always opt to keep the '-w' and remove the 'use warnings' line. There are slight differences between the two methods of enabling warnings, but I won't get into the gory details. In most cases, either one will do just fine. And to make your life even easier, you can place your $books{'fred'} = 3; $books{'wilma'} = 1; declarations within the hash when you create it. A modified version (with an initialized $someone variable might look something like this:

#!/usr/bin/perl -w use strict; my %books = ( fred => 3, wilma => 1, barney => 0, pebbles => undef ); my $someone = 'wilma'; if ($books{$someone}) { # Let's fancy it up: show how many books they have! print "$someone has $books{$someone} books checked out\n"; }


Update: P.S: Welcome to the Monastery! ++ to you on your first post here, hopefully it will be the first of many. I'd like to congratulate you on that script. You used warnings, strict, and somehow managed to figure out that we like to use <code> tags around here. Hope to see you around some more :)


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.


In reply to Re: Uninitialized value! by Coruscate
in thread Uninitialized value! by st_possenti

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.