Switch, Ranges and Memory



When using the range operator, is the list actually created with all the
elements?

For example, if I create a list like (123..456754), does it take up the
same amount of memory as if I actually entered all those in between
numbers?



I'm asking because I want to use ranges in a switch statement and they
are large ranges like the above. I don't think I can use >= in the case
section of the switch can I?



I think the code below will cause memory problems. Is there a better way
using switch? Or am relegated to using if statements with ">="?



my $flag_value = $field_array[9];

while ($flag_value < 0) {

switch ($flag_value) {

case 1 { $block{"WeightItem"} = "Y";
$flag_value -= 1 }

case [2, 3] { $block{"EnterPriceUsed"} = "Y";
$flag_value -= 2 }

case [4..7] { $block{"PriceRequired"} = "Y";
$flag_value -= 4 }

case [8..15] { $block{"LogItemExcpt"} = "Y";
$flag_value -= 8 }

case [16..31] { $block{"CodeFromAlias"} = "Y";
$flag_value -= 16 }

case [32..255] { $block{"NoMovement"} = "Y";
$flag_value -= 32 }

case [256..511] { $block{"EmpDiscount"} = "Y";
$flag_value -= 256 }

case [512..1023] { $block{"KeyedPrice"} = "Y";
$flag_value -= 512 }

case [1024..2047] { $block{"NonDiscntable"} = "Y";
$flag_value -= 1024 }

case [2048..4095] { $block{"WghtQtyEnt"} = "Y";
$flag_value -= 2048 }

case [4096..8191] { $block{"VoidItem"} = "Y";
$flag_value -= 4096 }

case [8192..16383] { $block{"RefndEntered"} = "Y";
$flag_value -= 8192 }

case [16384..32767] { $block{"LogExcptCond"} = "Y";
$flag_value -= 16384 }

case [32768..65535] { $block{"PrhibMultCoup"} = "Y";
$flag_value -= 32768 }

case [65536..131071] { $block{"AmtTypeAutoMarkdown"} =
"Y"; $flag_value -= 65536 }

case [131072..262143] { $block{"VoidAllItem"} = "Y";
$flag_value -= 131072 }

case [262144..524287] { $block{"ErrCorrectVoidItem"} =
"Y"; $flag_value -= 262144 }

case [524288..33554431] { $block{"Nsc2PricedItems"} =
"Y"; $flag_value -= 524288 }

case [33554432..67108863] { $block{"ItemOnSale"} = "Y";
$flag_value -= 33554432 }

case [67108864..101711679] { $block{"ManualWeight"} = "Y";
$flag_value -= 67108864 }

}

}



Thanks,



Barron





Relevant Pages

  • Re: Why doesnt "switch" statement have "break" as default?
    ... The 'C' switch statement is in no way syntactic sugar for a cascade of if-else ... I do realise that the compiler and/or JIT is allowed to implement any ... As to the proposal to add lists and ranges, a couple of comments, not entirely ... and those limits would translate into apparently arbitrary (and very ...
    (comp.lang.java.programmer)
  • PLL ratios (was Re: Dual-frequency quartz oscillator with a FPGA ?)
    ... Now if you have a smart idea about how to switch between them ... I'll have to divide this by 149 or 160 to obtain the right frequency. ... The Actel PLL has only 7-bit ratios, ... and the PLL's VCO ranges from 24 to 350MHz:-/ ...
    (comp.arch.fpga)
  • Re: Auto populate field with 100 different number range
    ... of the underlying business purpose or need can help clarify what needs to ... ranges"), but left out the WHAT or WHY. ... possible ranges under this switch. ... But this TCIC is divided into ranges of 24 (24 TCICs ...
    (microsoft.public.access.forms)
  • Re: Switch for floating !!
    ... int main ... Is it so difficult for C library to support the floating point ... Switch is designed to work with integer values only. ... ranges, and not distinct values. ...
    (comp.lang.c)
  • Re: Falling through on switch-cases
    ... >> The compiler should simply generate a compile error if the ranges ... should consider the possibility of a more flexible switch. ... case dayofweek.Monday: dostuff(); break; ... Also, as someone else pointed out, the ++ operator for enums should loop. ...
    (microsoft.public.dotnet.languages.csharp)