On Tue, Jul 31, 2001 at 10:21:47PM +0200, Matija Papec wrote:
> Michael Fowler <[EMAIL PROTECTED]> wrote:
> >Your restriction that it not use a for loop to construct the data is
> >needlessly limiting.  There are several ways to do what you ask, one of them
> >is a for loop.
> 
> I didn't like idea where "for" is used for adding elements one by one..
> otherwise I don't have anything at all against using it. ;)

You may not like it, but it's a needless restriction; the problem may call
for it.

 
> >    push(@{ $data[0] }, "") for (0 .. $#datumi2);
> >
> >OR
> >
> >    push(@{ $data[0] }, "") for @dataumi2;
> 
> Does $_ change in these two examples? (due cycling trough @datumi2)

I'm not using $_ in any of the examples; it's implicitly used by the for
loop as an iterator, but for the variable to be modified I would have to do
something with it.


> Can you explain where are these strengths(which one is the fastest?)

Given:
    1) push(@{ $data[0] }, "") for (0 .. $#datumi2);
    2) push(@{ $data[0] }, "") for @datumi2;
    3) $data[0] = [("") x @datumi2];

Offhand, I'd say the first two would be slower than the last; the first very
slightly slower than the second.  There is also readability to consider; the
last conveys quite a bit of meaning in few characters; the second could be
slightly confusing because it's iterating over an array, but doing nothing
with the values.

Don't take my word for it on relative speed, benchmark each.  Benchmark.pm
is good for doing this.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to