[16943] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4355 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 18 03:10:23 2000

Date: Mon, 18 Sep 2000 00:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969261012-v9-i4355@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 18 Sep 2000     Volume: 9 Number: 4355

Today's topics:
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator <jeffp@crusoe.net>
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator <tony-news@develop-help.com>
    Re: Using range operator <jeffp@crusoe.net>
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator <jeffp@crusoe.net>
    Re: Using range operator (Logan Shaw)
    Re: Using range operator (Logan Shaw)
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator (Logan Shaw)
    Re: Using range operator <uri@sysarch.com>
    Re: Using range operator <uri@sysarch.com>
    Re: Using range operator <randy_734@my-deja.com>
    Re: Using range operator <godzilla@stomp.stomp.tokyo>
    Re: Using range operator <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 17 Sep 2000 21:21:44 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C59858.233C5D46@stomp.stomp.tokyo>

Jeff Pinyan wrote:
 
> I'm taking DSA (Data Structures & Algorithms) this year in college, so I
> consider myself learned enough to make the follow statements...

Well, if you want to read some bragging. I hold a Bachelor's, a Master's
and a Ph. D. in English, specialty field, Creative Writing. I also hold
a B.Sc in Earth Science, which covers just about every science from
Astronomy to Zoology. Currently I am eight units shy of a B.A in
Cultural Anthrology. I am also credentialed, in the state of California,
to teach Primary level school and seven different single subjects, at
the Secondary level in school. This year, I am starting my nineteenth
year as a university student. Not only that, I can throw a baseball
like a boy!

I consider myself learned enough to make the follow statement,

"I wouldn't trade my common sense for all the education ever."


(snipped nice code)

 
> ...  Time and memory, "Godzilla," are NOT interchangeable, 
> nor are they techno-babble.  

Somebody say they are interchangable? 

* looks around suspiciously *

Ok, who is the wiseacre telling Mr. Pinyan Time and Memory
are interchangable? Probably some Intellectual-Geekster
heavy into Socratic Irony, Metaphysics and Carlos Castanada.


> As for the extendability of your loop, I would do something all
> crazy and obfuscated in the Perl 5 fashion of things...

I would do it all crazy, but not obfuscated, say, you ever
notice "obfuscated" has a dirty word sound to it? Anyhow,
I would do it schizoid in plain English Perl 4 so Perl 5
Cargo Cultists can understand it, then totally wig out.


> Oh no, that uses REFERENCES.  Not a difficult concept.

If References are not a difficult concept,
why are you wigging out?


> It's quite efficient, if you ask me.

Would you like me to ask you?


> and, well, don't get me started on $array[INFINITY].

Ok.. no problemo. Relax guy. Wouldn't want ya 
to wig out over slippery semantics, double meanings,
inverted puns and, especially a British Litotes.


Godzilla!
-- 
@© = (a .. z); @® = qw (7 15 4 26 9 12 12 1 18 15 3 11 19);
srand(time() ^ ($$ + ($$ << 15))); for ($§ = $®[$®[0]];
$§ < $®[0]-2; $§++){ sub G { rand(1000) < 500 ? "\u$1" : "\l$1" ; }
foreach $¿ (@®) { $¢ = $©[$¿-1]; $¢ =~ s¡([a-z])¡G($1)¡gie;
$Ø = "$Ø$¢"; } $Ø ="$Ø! "; $ø = substr ($Ø, $®[12] - $®[11], 0, " ");
$Ø =~ s¯(a)(r)¯$1 $2¯i; push (@Ø,$Ø); } foreach $¡ (@Ø) 
{ print "$¡\n"; } @¶ = reverse (@Ø); foreach $¶ (@¶)
{ print "$¶\n"; } exit;


------------------------------

Date: Mon, 18 Sep 2000 00:35:34 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Using range operator
Message-Id: <Pine.GSO.4.21.0009180033110.28758-100000@crusoe.crusoe.net>

On Sep 17, Godzilla! said:

>> ...  Time and memory, "Godzilla," are NOT interchangeable, 
>> nor are they techno-babble.  
>
>Somebody say they are interchangable? 

Perhaps I mis-read or mis-understood one of your previous posts.  If so, I
made a mistake.

>> Oh no, that uses REFERENCES.  Not a difficult concept.
>
>If References are not a difficult concept,
>why are you wigging out?

When did I wig out?  By responding to your post?  By using the word
'references' in all caps?  By writing clear and concise code, despite my
"crazy and obfuscated" hyperbole?

>> and, well, don't get me started on $array[INFINITY].
>
>Ok.. no problemo. Relax guy. Wouldn't want ya 
>to wig out over slippery semantics, double meanings,
>inverted puns and, especially a British Litotes.

What slippery semnatics, et. al., would those be?

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



------------------------------

Date: Sun, 17 Sep 2000 21:38:10 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C59C32.1300FB28@stomp.stomp.tokyo>

Randy wrote:
 
> Jeff,
 
> Pardon my butting in...

> I'm surprised to learn that range operator creates a list
> rather than a counter.  Given that, would you say that it
> is most always going to be more efficient to set up a loop
> with a counter rather than use a range, assuming the index
> is numeric?


If you can be a Buttinski, so can I!

Did you know Buttinski and Buttinsky
are recognized dictionary words????


A range operator is another way of saying array,
much like many Perl 5 Cargo Cultists mistakingly
call an associative array, "hash" which is fancy
dog food for people.

Efficiency is not so much a function of range operator
versus counter, but rather how well you limit your
range. An array, as Obsessive Techno-Geeksters would
have it, eats up memory, if large. A counter, also
as Perl 5 Cargo Cultists would have, eats up CPU time,
if a large range in count. Either way, both memory
and time are consumed, by both. Reality dictates, 
there is no practical difference between using an 
array and using a counter for circumstances of 
this thread.

Trick is in creating an effective range with
which to work. This is why my code allows input
arguments, for range control, where other codes
posted, as is, make no allowance for range control.
My code is user configurable for efficiency. Other
code posted, is fixed and not configurable, as is.

My code is imaginitive well planned Perl 4 style.
Other codes posted, although they work and all,
are stereotypical Perl 5 Cargo Cult code which
is sorely lacking for practical usage.

* ducks flying rotten eggs and old tomatoes *


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


------------------------------

Date: Mon, 18 Sep 2000 16:06:59 +1100
From: Tony Cook <tony-news@develop-help.com>
Subject: Re: Using range operator
Message-Id: <39C5A2F3.56725B03@develop-help.com>

Jeff Pinyan wrote:
>...
> up a lot more TIME:
> 
>   for ($i = 0; $i < 1_000_000_000; $i++) {}
> 
> than this one:
> 
>   for ($i = 0; $i < 10; $i++) {}
> 
> But both take far less MEMORY than:
> 
>   for $i (0..999_999_999) {}
> 
> This is because the range operator builds a list (in this case, a list of
> 10^9 elements), and lists are stored in memory.  Larger lists require
> larger amounts of memory.

The list is optimized away in current versions of Perl.  Both:

    for $i (1..10) { }

and

    for $i (1..1_000_000_000) { }

use the same amount of memory.

Note from man perlop:

                                                This is useful
       for writing foreach (1..10) loops and for doing slice
       operations on arrays.  In the current implementation, no
       temporary array is created when the range operator is used
       as the expression in foreach loops, but older versions of
       Perl might burn a lot of memory when you write something
       like this:

           for (1 .. 1_000_000) {
               # code
           }

Tony


------------------------------

Date: Mon, 18 Sep 2000 00:52:55 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Using range operator
Message-Id: <Pine.GSO.4.21.0009180036430.28758-100000@crusoe.crusoe.net>

[posted & mailed]

On Sep 18, Randy said:

>I'm surprised to learn that range operator creates a list rather than
>a counter.  Given that, would you say that it is most always going to
>be more efficient to set up a loop with a counter rather than use a
>range, assuming the index is numeric?

Python offers both a range() function and an xrange() function.  The
xrange() returns an object that returns the next value in its sequence.
You could make such functionality in Perl by tie()ing a scalar, or a
function.

  sub make_counter {
    my ($low,$high,$step);
    if (@_ == 1) { ($low,$high,$step) = (0,@_,1) }
    elsif (@_ == 2) { ($low,$high,$step) = (@_,1) }
    else { ($low,$high,$step) = @_ }
    return sub {
      my $ret = $low;
      $low += $step;
      return $ret >= $high ? undef : $ret;
    };
  }
  
  $counter = make_counter(10);
  while (defined($x = $counter->())) {
    print "$x ";
  }

Will print 0 through 9.  You can offer a starting value other than 0, and
a step value other than 1.

As for which is better, here's a benchmark:

  #!/usr/bin/perl
  use Benchmark;
  timethese(1_000, {
    'C-style 100' => q{ for ($i = 0; $i < 100; $i++) { } },
    'C-style 10_000' => q{ for ($i = 0; $i < 10_000; $i++) { } },
    'Perl-style 100' => q{ for $i (0 .. 99) { } },
    'Perl-style 10_000' => q{ for $i (0 .. 9_999) { } },
  });

The output:

Benchmark: timing 1000 iterations of C-style 100, C-style 10_000,
Perl-style 100, Perl-style 10_000...
C-style 100:  1 wallclock secs ( 0.67 usr +  0.00 sys =  0.67 CPU)
C-style 10_000: 64 wallclock secs (61.62 usr +  0.01 sys = 61.63 CPU)
Perl-style 100:  1 wallclock secs ( 0.64 usr +  0.00 sys =  0.64 CPU)
Perl-style 10_000: 57 wallclock secs (57.26 usr +  0.00 sys = 57.26 CPU)

But as this message thread will show you, the (0 .. 9_999) method uses
more memory than the C-style loop.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



------------------------------

Date: Sun, 17 Sep 2000 21:57:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C5A0D2.CE87AB76@stomp.stomp.tokyo>

Jeff Pinyan wrote:
 
> On Sep 17, Godzilla! said:

I did NOT! I wrote, I never said.
Why did you accuse me of saying
something when you know this is
a textual format, only???? Well?

 
> What slippery semnatics, et. al., would those be?
 
You are a good sport! This is a good reflection upon you.

Slippery Semantics show up very frequently, Mr. Pinyan.
I am, inherently, a Mistress of Slippery Semantics. Still,
wasn't my intent to use those in this thread. Just sorta
turned out that way; misunderstanding of meaning.

However, you ask about Slippery Semantics. Here is a classic,
Obsessive Techno-Geeksters trip over constantly, "CPU".
Central Processing Unit has two meanings and is context
sensitive. One meaning, if you are talking from an overall
hardware perspective, is "CPU" means your tower, your
processor, your sound card, your whatever including
your box housing it all. When you discuss a processor
chip, "CPU" means just that; a processor chip.

A problem, Mr. Pinyan, with becoming so specialized in
one field, is a loss of common vernacular, an oxymoronic
expression in itself. This notion cuts across all fields
of speciality, even mine, English. Should I elect to
communicate in a style of which I am accustomed, people
would scream and accuse myself of being a snoot.

Rahhhhly Dahhhhling, I know in my heart they would.

So, Memory ~ Time are quite interchangable when used
as loose common day expressions. Technically no, maybe.
Very hard to sort memory from time. Both are functions
of each other; interwoven like a spider web. More use
of memory, usually means more use of CPU time. More
use of CPU time, usually means more use of memory.
Still, if I jump into Tron with Kirk Douglas' youngest
son, Memory and Time are very sorted out. This is
not Tron though and, we are not Borgs.

Get it?

If not, hang onto your hat when you are traveling
at velocity C. Hats tend to fly off at this
high velocity.

I will consider a dictionary attachment for my
articles to assist those who.. who whatever...


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


------------------------------

Date: Mon, 18 Sep 2000 00:58:41 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Using range operator
Message-Id: <Pine.GSO.4.21.0009180057540.28758-100000@crusoe.crusoe.net>

On Sep 18, Tony Cook said:

>Jeff Pinyan wrote:
>>...
>> up a lot more TIME:
>> 
>>   for ($i = 0; $i < 1_000_000_000; $i++) {}
>> 
>> than this one:
>> 
>>   for ($i = 0; $i < 10; $i++) {}
>> 
>> But both take far less MEMORY than:
>> 
>>   for $i (0..999_999_999) {}
>> 
>> This is because the range operator builds a list (in this case, a list of
>> 10^9 elements), and lists are stored in memory.  Larger lists require
>> larger amounts of memory.
>
>The list is optimized away in current versions of Perl.  Both:
>
>    for $i (1..10) { }
>
>and
>
>    for $i (1..1_000_000_000) { }
>
>use the same amount of memory.

D'oh, you're right.  I was thinking more along the lines of

  @array = (1 .. 1_000_000_000);

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



------------------------------

Date: 17 Sep 2000 23:59:37 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Using range operator
Message-Id: <8q47fp$pu7$1@provolone.cs.utexas.edu>

In article <Pine.GSO.4.21.0009172306240.28758-100000@crusoe.crusoe.net>,
Jeff Pinyan  <japhy@pobox.com> wrote:
>I'm taking DSA (Data Structures & Algorithms) this year in college, so I
>consider myself learned enough to make the follow statements:
>
>  int i;
>  for (i = 0; i < N; i++) {
>    1;
>  }
>
>That block of C code is O(N).  That means, it performs its actions in a
>time proportional to N.  PROPORTIONAL TO N.  If N is small, the loop takes
>a small amount of time to run.  As N gets bigger, the time increases.

Actually, the fact that its execution time is O(n) means that its
execution time, as a function of n, is a member of a set of functions
which each have the property that, if you take n greater than some
finite constant value, then there is another finite constant which
you can multiple by the function so that it's never greater than n.

In other words, O(n) is the set of functions f(n) which have the
property that there exists a finite constant c > 0 such that for
all n > N (where N is a finite constant), c * f(n) <= n.

Or, O(n) = { f(n) | exists c > 0 s.t. for all n > N, c * f(n) <= n } .

Or, in layman's terms, you can pick a number of initial values of f(n)
to ignore such that the remaining ones are not greater than some
function that's proportional to n.

  - Logan


------------------------------

Date: 18 Sep 2000 00:04:54 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Using range operator
Message-Id: <8q47pm$pva$1@provolone.cs.utexas.edu>

In article <39c591bd.43516796@207.126.101.100>,
Randy  <randy_734@my-deja.com> wrote:
>Pardon my butting in...

Yeah, God forbid we should discuss something about Perl here...  :-)

>I'm surprised to learn that range operator creates a list rather than
>a counter.  Given that, would you say that it is most always going to
>be more efficient to set up a loop with a counter rather than use a
>range, assuming the index is numeric?

Not always -- I can imagine that

	for (1 .. 3)
		{
		# loop body
		}

might be faster than

	for (my $x = 0; $x < 3; $x++)
		{
		# loop body
		}

But, for loops that loop over large ranges, the range operator is
probably not going to be the efficient way to do it.  Except in recent
versions of perl, which claim that "in the current implementation, no
temporary array is created when the range operator is used as the
expression in `foreach' loops."

Also note that the range operator does one thing in scalar contexts and
another thing in list contexts.  "perldoc perlop" and read the section
called "Range Operators" for more info.

  - Logan


------------------------------

Date: Sun, 17 Sep 2000 22:16:38 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C5A536.3D8ADD40@stomp.stomp.tokyo>

Tony Cook wrote:
 
> Jeff Pinyan wrote:
 
> The list is optimized away in current versions of Perl.  Both:
 
>     for $i (1..10) { }
 
> and
 
>     for $i (1..1_000_000_000) { }
 
> use the same amount of memory.


Is there a trade-off somewhere not discussed
in documentation? Maybe additional CPU Time
due to extra processing of large numbers,
within stated parameters.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


------------------------------

Date: 18 Sep 2000 00:17:55 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Using range operator
Message-Id: <8q48i3$q1e$1@provolone.cs.utexas.edu>

In article <39C5A0D2.CE87AB76@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>So, Memory ~ Time are quite interchangable when used
>as loose common day expressions. Technically no, maybe.
>Very hard to sort memory from time. Both are functions
>of each other; interwoven like a spider web. More use
>of memory, usually means more use of CPU time. More
>use of CPU time, usually means more use of memory.

Actually, for a really large number of computation problems, it's
the case that there is more than one algorithm that can be used, and
one uses more memory and less CPU, while another uses less memory
and more CPU.  In other words, a common theme with algorithms is
that you are often choosing whether to sacrifice memory to get more
speed or to sacrifice speed to save memory.  Caches are a simple
example; they use memory, but they speed things up overall.  Of
course, there are exceptions to this rule -- some algorithms are
just clever and use both less space and less time; others are just
silly and use more of both -- but overall it's usually a trade-off.

  - Logan


------------------------------

Date: Mon, 18 Sep 2000 05:24:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using range operator
Message-Id: <x77l8aff18.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

  G> Efficiency is not so much a function of range operator
  G> versus counter, but rather how well you limit your
  G> range. An array, as Obsessive Techno-Geeksters would
  G> have it, eats up memory, if large. A counter, also
  G> as Perl 5 Cargo Cultists would have, eats up CPU time,
  G> if a large range in count. Either way, both memory
  G> and time are consumed, by both. Reality dictates, 
  G> there is no practical difference between using an 
  G> array and using a counter for circumstances of 
  G> this thread.

you are bonkers but what else is new. you have no clear concepts of memory
vs. time in a computer context. 

  G> Trick is in creating an effective range with
  G> which to work. This is why my code allows input
  G> arguments, for range control, where other codes
  G> posted, as is, make no allowance for range control.
  G> My code is user configurable for efficiency. Other
  G> code posted, is fixed and not configurable, as is.

huh? you code was slow and stupid. a simple sub like this works as well
and is much faster:

sub in_range {

	my( $val, $low_range, $high_range ) = @_ ;

	$low_range <= $val && $val <= $high_range ;
}

1 line of code, has all the programmbility of yours and it is faster.

  G> My code is imaginitive well planned Perl 4 style.
  G> Other codes posted, although they work and all,
  G> are stereotypical Perl 5 Cargo Cult code which
  G> is sorely lacking for practical usage.

  G> * ducks flying rotten eggs and old tomatoes *

you didn't duck fast enough. you are covered in them in this
thread. even more so than the usual pile heaped upon you. ever wonder
why you have no friends or backers here? even 1 person who agrees with
you most of the time? or anyone who regularly refers to your posts?
notice how no one ever says something like: "or you could use the code
moronzilla posted"?

it is because you don't know anything about programming nor about perl.

get lost already.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Mon, 18 Sep 2000 05:29:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using range operator
Message-Id: <x74s3efeu2.fsf@home.sysarch.com>

>>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:

  LS> Actually, for a really large number of computation problems, it's
  LS> the case that there is more than one algorithm that can be used, and
  LS> one uses more memory and less CPU, while another uses less memory
  LS> and more CPU.  In other words, a common theme with algorithms is
  LS> that you are often choosing whether to sacrifice memory to get more
  LS> speed or to sacrifice speed to save memory.  Caches are a simple

we are wasting our collective breath trying to educate moronzila on
spcae vs. time tradeoffs. the fact that you can program any single
argument function with a massive lookup table and return the result in
constant time is meaningless to her.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Mon, 18 Sep 2000 05:55:21 GMT
From: Randy <randy_734@my-deja.com>
Subject: Re: Using range operator
Message-Id: <39c5ad1a.50521187@207.126.101.100>

Actually it was reading perlop that caused me to ask the question in
the first place, about using the range operator for comparison rather
than counting.

    if (101 .. 200) { print; }  # print 2nd hundred lines

This line came from perlop and at first glance it looked as though it
were doing a comparison, but I can see now that it is simply iterating
the input lines.  Closer scrutiny revealed that its default behaviour
is to count the $. variable.

My thanks to all for the enlightening discussion.
Randy


logan@cs.utexas.edu (Logan Shaw) wrote:

>In article <39c591bd.43516796@207.126.101.100>,
>Randy  <randy_734@my-deja.com> wrote:
>>Pardon my butting in...
>
>Yeah, God forbid we should discuss something about Perl here...  :-)
>
>>I'm surprised to learn that range operator creates a list rather than
>>a counter.  Given that, would you say that it is most always going to
>>be more efficient to set up a loop with a counter rather than use a
>>range, assuming the index is numeric?
>
>Not always -- I can imagine that
>
>	for (1 .. 3)
>		{
>		# loop body
>		}
>
>might be faster than
>
>	for (my $x = 0; $x < 3; $x++)
>		{
>		# loop body
>		}
>
>But, for loops that loop over large ranges, the range operator is
>probably not going to be the efficient way to do it.  Except in recent
>versions of perl, which claim that "in the current implementation, no
>temporary array is created when the range operator is used as the
>expression in `foreach' loops."
>
>Also note that the range operator does one thing in scalar contexts and
>another thing in list contexts.  "perldoc perlop" and read the section
>called "Range Operators" for more info.
>
>  - Logan



------------------------------

Date: Sun, 17 Sep 2000 22:58:08 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Using range operator
Message-Id: <39C5AEF0.BCC8FCA@stomp.stomp.tokyo>

Logan Shaw wrote:
 
> In article <39C5A0D2.CE87AB76@stomp.stomp.tokyo>,
> Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> >So, Memory ~ Time are quite interchangable when used
> >as loose common day expressions. Technically no, maybe.
> >Very hard to sort memory from time. Both are functions
> >of each other; interwoven like a spider web. More use
> >of memory, usually means more use of CPU time. More
> >use of CPU time, usually means more use of memory.
 
> Actually, for a really large number of computation problems, it's
> the case that there is more than one algorithm that can be used, and
> one uses more memory and less CPU, while another uses less memory
> and more CPU.  In other words, a common theme with algorithms is
> that you are often choosing whether to sacrifice memory to get more
> speed or to sacrifice speed to save memory.  Caches are a simple
> example; they use memory, but they speed things up overall.  Of
> course, there are exceptions to this rule -- some algorithms are
> just clever and use both less space and less time; others are just
> silly and use more of both -- but overall it's usually a trade-off.


This word, "usually", seems a key expression, contrasting
our word, "exception", yes?

Speaking in an exceptional notion, rather than a usual notion,
yes. So from a practical perspective, you end up striking a
mutually equitable bargin between speed and memory. Thus,
speed and memory are interchangable, quite clearly. They are
in direct inverted proportion, or inversely proportionate,
as math geeks would say, much like my Mako Shark. 

If I cruise at fifty-five in my Mako Shark and, I can't 
drive fifty-five, oh yeah!, my gas mileage is moderately
decent. If I press my pedal to the metal, I can hit a nice
one-eighty-five in a hurry and, my fuel tank implodes.

Either way, Vegas in under four hours or Vegas in
under two hours, my fuel tank is empty upon arrival.
Odd how my Mako Shark violates physical laws and
written laws, as well.

However, general rule of green thumb is, more memory
usage usually means slower speed and quite the inverse,
for common everyday applications; the usual.

It's all semantics, in a nit picking final analysis.

Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


------------------------------

Date: Mon, 18 Sep 2000 05:58:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using range operator
Message-Id: <x7zol6dywh.fsf@home.sysarch.com>

>>>>> "R" == Randy  <randy_734@my-deja.com> writes:

  R> Actually it was reading perlop that caused me to ask the question in
  R> the first place, about using the range operator for comparison rather
  R> than counting.

  R>     if (101 .. 200) { print; }  # print 2nd hundred lines

  R> This line came from perlop and at first glance it looked as though it
  R> were doing a comparison, but I can see now that it is simply iterating
  R> the input lines.  Closer scrutiny revealed that its default behaviour
  R> is to count the $. variable.

you were confusing the scalar context .. with the array context ..

they are very different animals even though they share the operator and
name (they are both ranges of a sort).

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4355
**************************************


home help back first fref pref prev next nref lref last post