iThunder has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: program doesnt work for all elements of the array
by kcott (Archbishop) on Oct 18, 2013 at 08:44 UTC
Re: program doesnt work for all elements of the array
by ww (Archbishop) on Oct 18, 2013 at 11:16 UTC

    As others have asked, clean up the formatting of your post, with para and code tags. Then go back to your code and:

    1. Format with consistent indentation
    2. use strict; use warnings;
    3. Fix the warning items
    4. Fix the errors
    5. Test your corrections with perl -c wordguess.pl (or whatever name you're using for the code)
    6. Wash, rinse, repeat.
    7. When no warnings or errors are issued at 6, try to execute the program.
    8. (late addition: ) Now you're ready to insert debug statements to find your logical errors

    If you get stuck, come back and show us (partially) corrected code and any msgs when you execute.

Re: program doesnt work for all elements of the array
by lune (Pilgrim) on Oct 18, 2013 at 08:48 UTC
    And please also add your wordslist.txt
Re: program doesnt work for all elements of the array
by talexb (Chancellor) on Oct 18, 2013 at 13:28 UTC

    This is going to sound old-fashioned, but I'd recommend you spend some time in the Perl debugger. You can try out individual syntaxes, dump out variables, and get a feel for the language.

    For example, you have syntax like @words1$a = $name;; it looks like you're trying to add $name to the words1 array at index $a. You haven't done this before, because that's the wrong syntax; and in any case, push is normally used to add elements to an array. Also, $a and $b are special variables used only in sort blocks -- it's not forbidden to use them, but it's considered bad style.

    It's also handy to write yourself a comment or two so you have a good idea of what each piece of code is supposed to do. This will also help others understand what the code is meant to do.

    O'Reilly's Learning Perl is a great starter book for this language.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.