Hi, I'm trying to learn Perl and every now and then I run into an error on a script that I think ought to be correct. I'm not sure if I have an obvious error somewhere or not but my IDE keeps saying there is an error at line 6 (error: Can't modify not in scalar assignment). I was thinking maybe my close parenthesis or semicolon at the end of the hash is off. However, modifying that line/area doesn't seem to fix things. I'm posting the code for some help please.
!#/usr/bin/perl %words = qw(Sarah cat Bob dog Ronald apple Eric banana); print "What is your name?"; $name = <STDIN>; chomp ($name); if ($name eq "Jerry") { print "Hi, Jerry! Have a good day!\n";} else {print "Hello, $name!\n"; #normal greeting $secretword = $words{$name}; #get the secret word print "Guess the secret word.\n"; $guess = <STDIN>; chomp ($guess); while ($guess ne $secretword) { print "I'm sorry. That is not the correct word. Please try again. + What is the secret word?"; $guess = <STDIN>; chomp ($guess); } }

In reply to Creating a Hash Syntax Error by ms238

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.