Re: Switch, Ranges and Memory



On 8/29/06, Barron Snyder (CE CEN) <Barron.Snyder@xxxxxxxxxxxxxx> wrote:

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?

Generally, 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?

It depends. What programming language are you talking about? Perl
doesn't have case/switch statements, although there are some extension
modules that add that functionality. If you're using one of those
extension modules, you should check its documentation to see what it
allows.

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

Each of your cases seems to begin on a power-of-two. Would you be
really happy to discover the function int(log2($something))?

sub log2 { log($_[0]) / log(2) }

The Perl FAQ has an extensive list of ways to write switch/case
statements in Perl. Perhaps one of those will be useful, with or
without log2.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
.



Relevant Pages

  • dynamically loading perl modules
    ... We are starting to build a small web portal in perl. ... Already at this stage we see the need to be able to plug-in certain functionality. ... Is the first strategy good at all, or should we aim for the second? ... How can we dynamically load a module? ...
    (comp.lang.perl.misc)
  • Re: JavaScript Variable Interpolation, Take II
    ... Another option would be to install free ActivePerl and then use Perl ... Concerning the string interpolation functionality you are seeking for: ... indeed Javascript completely misses it. ...
    (comp.lang.javascript)
  • Re: Detect open windows shares?
    ... The product is to be written in Perl and provide NMAP-type ... functionality, plus more, in order to aid a network administrator in ... functions I would like to provide is the ability to scan a network for ... Maybe thats why so little in the core. ...
    (comp.lang.perl.misc)
  • Re: Custom PM Modules Wont Work
    ... divide the functionality into modules but as soon as I try I get the error ... Can someone give me a simple example Perl script that uses a module so I ... package Foo; ...
    (comp.lang.perl.modules)
  • Re: Detect open windows shares?
    ... I am developing a product as part of a university assignment. ... The product is to be written in Perl and provide NMAP-type ... functionality, plus more, in order to aid a network administrator in ... functions I would like to provide is the ability to scan a network for ...
    (comp.lang.perl.misc)