Results 1 to 2 of 2

Thread: Perl : Improve this group of if statements ?=

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Perl : Improve this group of if statements ?=

    I have the following piece of code in perl.
    I'm sure there must be a better way of doing this... but I don't know very much about perl.

    Any ideas ?

    Code:
    if ($ipAddress[0] == 61)  {
    	$which = 2;
    } elsif ($ipAddress[0] == 62) {
    	$which = 0;
    } elsif (($ipAddress[0] >= 63) && ($ipAddress[0] <= 69))   {
    	$which = 1;
    } elsif (($ipAddress[0] == 80) || ($ipAddress[0] == 81))   {
    	$which = 0;
    } elsif (($ipAddress[0] >= 128) && ($ipAddress[0] <= 192)) {
    	$which = 1;
    } elsif (($ipAddress[0] >= 193) && ($ipAddress[0] <= 195)) {
    	$which = 0;
    } elsif ($ipAddress[0] == 196) {
    	$which = 3;
    } elsif ($ipAddress[0] == 198) {
    	$which = 1;
    } elsif (($ipAddress[0] >= 193) && ($ipAddress[0] <= 195)) {
    	$which = 0;
    } elsif (($ipAddress[0] >= 199) && ($ipAddress[0] <= 201)) {
    	$which = 1;
    } elsif (($ipAddress[0] >= 202) && ($ipAddress[0] <= 203)) {
    	$which = 2;
    } elsif (($ipAddress[0] >= 204) && ($ipAddress[0] <= 209)) {
    	$which = 1;
    } elsif (($ipAddress[0] >= 210) && ($ipAddress[0] <= 211)) {
    	$which = 2;
    } elsif (($ipAddress[0] >= 212) && ($ipAddress[0] <= 213)) {
    	$which = 0;
    } elsif (($ipAddress[0] >= 214) && ($ipAddress[0] <= 215)) {
    	$which = 1;
    } elsif ($ipAddress[0] == 216) {
    	$which = 1;
    } elsif ($ipAddress[0] == 217) {
    	$which = 0;
    } elsif (($ipAddress[0] >= 218) && ($ipAddress[0] <= 221)) {
    	$which = 2;
    } elsif ($ipAddress >= 222) {
    	$which = 1;
    }
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    i dont know perl, but i think its kinda like C

    so could you try this.

    Code:
    switch($ipAddress[0])
    {
    case 62
    $which = 0;
    break;
    }
    dont hold me to this though

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width