Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Perl "if" condition question.

Expand Messages
  • Luinrandir Hernsen
    I am writing a game and I am trying to determine, if a player owns certain castles then he is king of that area. Your code looks like it loops checking for a
    Message 1 of 5 , Feb 23, 2005
    • 0 Attachment
      I am writing a game and I am trying to determine, if a player owns certain castles then he is king of that area.
      Your code looks like it loops checking for a true many time.. I need them all true at the same time to declare you a "king" of the area.

      Luinrandir
      ----- Original Message -----
      From: Mike Dillinger
      To: perl-beginner@yahoogroups.com
      Sent: Monday, February 21, 2005 2:02 PM
      Subject: Re: [PBML] Perl "if" condition question.





      Message from "Luinrandir Hernsen" on 02/21/05 08:37 AM PT quoted:
      > Merlyn... wrap your head in duct tape before reading lest your head explode.
      > You once asked to see some of my code.. here it is! LOL
      >
      > Everyone.....
      > My current code is.
      >
      > if ( $DataC[1] eq "$Playername"
      > && $DataC[4] eq "$Playername"
      > && $DataC[7] eq "$Playername"
      > && $DataC[11] eq "$Playername"
      > && $DataC[12] eq "$Playername"
      > && $DataC[22] eq "$Playername"
      > && $DataC[32] eq "$Playername"
      > && $DataC[33] eq "$Playername"
      > && $DataC[40] eq "$Playername"
      > && $DataC[51] eq "$Playername"
      > )
      > {
      > #do stuff
      > }
      >
      > How do I make the condition smaller?

      foreach my $elem ( 1, 4, 7, 11, 12, 22, 32, 33, 40, 51 )
      {
      if( $DataC[ $elem ] eq "$Playername" )
      {
      ...
      }
      }

      Hashes might work better for this, but it depends what you're doing.

      -MikeD


      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
      Yahoo! Groups Links








      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.