foreach performance

S

shurikgefter

Hi,

What is a better for performance:

1)
foreach my $key ( split ( ',' , $temp ) )
{
......
}

or

2)

@tmp = split ( ',' , $temp );
foreach my $key ( @tmp )
{
.....
}

Does the split command will be execute each foreach loop or only first
time?
 
X

Xho Jingleheimerschmidt

Hi,

What is a better for performance:

The catholic church was recently apologized for persecuting Galileo.
Why are you still afraid of the experimental method?
1)
foreach my $key ( split ( ',' , $temp ) )
{
......
}

or

2)

@tmp = split ( ',' , $temp );
foreach my $key ( @tmp )
{
.....
}

In my hands the first is faster. With your computer and your version of
Perl and your details of the construction of $temp, the results may be
different.
Does the split command will be execute each foreach loop or only first
time?

If it executed each time, you would likely have a infinite loop,
wouldn't you?


Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top