Re: what am I missing?

Discussion in 'Perl' started by Mark, Aug 25, 2003.

  1. Mark

    Mark Guest

    "fnord" <> wrote in message
    news:...
    > I've got this subroutine running:
    >
    > ##################################
    > # check to see if letters entered are really in the available array
    > #################################
    > sub lettersExist
    > {
    >
    > print "letters: $letters\n";
    > if ($vulnerable eq 0)
    > {
    > for ($place = 0; $place < $letters; ++$place)
    > {
    > if (@diceList =~ /@letterCheck[$place]/i)

    #<---------------- This seems to be the problem line to me.
    > #if (@diceList =~ @diceList)
    > {
    > print "$letters\n";
    > print "The letter is there\n";
    > }
    > else
    > {
    > print "@diceList \n";
    > print "@letterCheck[$place] \n";
    > print "$letters\n";
    > #$unavailable = 1;
    > print "Sorry, you used a letter that is

    unavailable.\n";
    > exit;
    > }
    > }
    > }
    > else
    > {
    > for ($place = 0; $place < 13; ++$place)
    > {
    > $availabilityChecker = @letterCheck[$place] =~

    /$letters/i;
    > print "$availabilityChecker\n";
    > }
    > }
    > }
    >
    >
    > I don't get why this isn't working. The "if (@diceList =~

    /@letterCheck[$place]/i)" statement should be returning true, but it always
    returns false. The print statements in the "else" statement show that the
    available letters (@diceList from the print statement) are:
    >
    > B O A I R L U V A H
    >
    > the @letterCheck[$place] value (from the print statement) is:
    >
    > b
    >
    > I've got the /i at the end of the regex, so it should be case insensitive,

    but this check still fails every time. I'm new to perl, and am stumped on
    this one.
    >
    > Can anyone see what I'm missing?
    >
    >
    > Thanks,
    > fnord


    When referring to $element of @foo, use $foo[$element] (note carefully the
    use of '@' and '$') . Refer to the entire array as @foo, but use $foo[] to
    refer to a single element (or group of elements as in $foo[0..3]). In the
    posted code the improper syntax appears in several places.

    Also, it is helpful to those who would Google for similar problems later if
    you use a meaningful subject line, perhaps: Array elements not incrementing
    as expected.
    Mark, Aug 25, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Fox
    Replies:
    0
    Views:
    744
    Paul Fox
    Mar 5, 2004
  2. Mark Newby
    Replies:
    1
    Views:
    1,697
  3. CodeMonkey
    Replies:
    0
    Views:
    407
    CodeMonkey
    Oct 11, 2005
  4. Acceed See
    Replies:
    1
    Views:
    525
    Carl W.
    Apr 22, 2005
  5. Gary Herron
    Replies:
    2
    Views:
    664
    Bruno Desthuilliers
    Jul 4, 2006
Loading...

Share This Page