As JavaFan has already pointed out, you don't check to see whether your open succeeded. The usual way to do this is the "do or die" idiom.

my $dict_file = '/usr/share/dict/words'; open my $dict_fh, '<', $dict_file or die "Can't read '$dict_file': $!";

Be sure to include $! in the error message when you die so you know why it didn't work.

I agree also with ikegami that you should Use strict and warnings.

The reason your @blankword winds up too long is that each of @words has a newline at the end of it. You can take care of that with chomp similar to how Ciclamino suggests or just do what you're doing now and then take care of @words before you select one.

open my $dict_fh ... my @words = <$dict_fh>; chomp @words;

I have not read the bulk of your code, so there could be more errors there as well.

As an aside, since you only ever select one word from your dictionary, you don't have to store the whole array of them. See How do I select a random line from a file?


In reply to Re: Assigning a file to an Array. by kyle
in thread Assigning a file to an Array. by elle45purple

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.