in reply to Help with Guessing Game

$allguess is not the same as @allguess. You are mixing sigils. You should use strict to avoid these problems. Moreover,
@allguess = $guess
overwrites the previous value of @allguess. Use push to add new elements to arrays.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Help with Guessing Game
by davido (Cardinal) on May 11, 2013 at 22:49 UTC

    The problem domain seems only to be limited to numbers between one and ten. Forget push :) Just use an array as a boolean vector.

    if ( $test[$guess]++ ){ print "Duplicate\n"; }

    Dave

Re^2: Help with Guessing Game
by dj_jodo (Initiate) on May 11, 2013 at 13:30 UTC

    I'm really confused at this point, my instructor told me to get all the guessing and put them in an array so are you saying I should use push to add onto the @allguess array each time the user enters a number. As you can see I'm very new to this, the other problem I'm having is using the grep function to see if the number has been guessed.

      1. I don't understand the intent of your first sentence here. Are you objecting that the PM solution offered (seems to you) to vary from your instructor's directions? If so, trust choroba's trouble-shooting. Push (see also next graf) allows you to add new elements to an array. When inside a loop, assigning a value to the array REPLACES whatever was in the array on the last iteration of the loop.
      2. Perhaps your instructor mentioned using your command line to obtain local help;
        C:\> perldoc -f push
        or
        C:\> perldoc -f grep
      There are many more sources of help local to your computer. See, for instance, perldoc perldoc and many others.

      If you didn't program your executable by toggling in binary, it wasn't really programming!