Re: Switch, Ranges and Memory



Barron Snyder (CE CEN) wrote:
When using the range operator, is the list actually created with all the
elements?

It depends. :-) In general, yes it does. See the "Range Operators" section
of perlop:

perldoc perlop


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?

Yes.

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 ">="?

It looks like you can use bitwise operators:

my $flag_value = $field_array[ 9 ];

$block{ WeightItem } = 'Y' if $flag_value & 0x00000001;
$block{ EnterPriceUsed } = 'Y' if $flag_value & 0x00000002;
$block{ PriceRequired } = 'Y' if $flag_value & 0x00000004;
$block{ LogItemExcpt } = 'Y' if $flag_value & 0x00000008;
$block{ CodeFromAlias } = 'Y' if $flag_value & 0x00000010;
$block{ NoMovement } = 'Y' if $flag_value & 0x00000020;
$block{ EmpDiscount } = 'Y' if $flag_value & 0x00000100;
$block{ KeyedPrice } = 'Y' if $flag_value & 0x00000200;
$block{ NonDiscntable } = 'Y' if $flag_value & 0x00000400;
$block{ WghtQtyEnt } = 'Y' if $flag_value & 0x00000800;
$block{ VoidItem } = 'Y' if $flag_value & 0x00001000;
$block{ RefndEntered } = 'Y' if $flag_value & 0x00002000;
$block{ LogExcptCond } = 'Y' if $flag_value & 0x00004000;
$block{ PrhibMultCoup } = 'Y' if $flag_value & 0x00008000;
$block{ AmtTypeAutoMarkdown } = 'Y' if $flag_value & 0x00010000;
$block{ VoidAllItem } = 'Y' if $flag_value & 0x00020000;
$block{ ErrCorrectVoidItem } = 'Y' if $flag_value & 0x00040000;
$block{ Nsc2PricedItems } = 'Y' if $flag_value & 0x00080000;
$block{ ItemOnSale } = 'Y' if $flag_value & 0x02000000;
$block{ ManualWeight } = 'Y' if $flag_value & 0x04000000;




John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • Re: Swap space
    ... > twice the amount of RAM if you need to capture a dump for debugging. ... > If you won't ever be doing that, you may not need so much swap. ... least the size of physical memory. ...
    (freebsd-questions)
  • Re: My idea of fully-portable C code
    ... unused state in the middle of a list of values will "use the least ... amount of memory possible" only by luck, ... The only thing that counts is what the code does if used within the limits you actually specified, on a random host platform implementing standard C. ...
    (comp.arch.embedded)
  • Re: Lambda Calculus and Turing Equivalence
    ... memory of a TM exceeds the potential finite memory of a PC. ... principle compute problems that require greater storage than ... That is because the tape that Turing posited has no physical constraints. ... magically given an infinite amount of storage space." ...
    (comp.theory)
  • Re: Lambda Calculus and Turing Equivalence
    ... memory of a TM exceeds the potential finite memory of a PC. ... principle compute problems that require greater storage than ... That is because the tape that Turing posited has no physical constraints. ... magically given an infinite amount of storage space." ...
    (sci.math)
  • Re: Problem - Solved - Re: Starting with Linux
    ... My laptop is a Pentium 133mz, with the 96mb RAM. ... With DMA off, you will notice some system degradation and with only ... > to 8Mb probably) further reducing the amount of system memory available. ...
    (alt.os.linux.suse)