Re: Switch, Ranges and Memory
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 29 Aug 2006 18:41:15 -0700
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
.
- References:
- Switch, Ranges and Memory
- From: Barron Snyder
- Switch, Ranges and Memory
- Prev by Date: Re: Can't create 2d array in Perl
- Next by Date: Re: splitting strings
- Previous by thread: Re: Switch, Ranges and Memory
- Next by thread: Can't create 2d array in Perl
- Index(es):
Relevant Pages
|
|