Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
more useful options
 
PerlMonks  

Re: Re: Strange benchmark result that has me totally confounded

by jpfarmer (Pilgrim)
on Apr 16, 2004 at 18:45 UTC ( [id://345900]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Strange benchmark result that has me totally confounded
in thread Strange benchmark result that has me totally confounded

But I'm not modifying @messages, am I?

Unless I'm missing something, I'm only modifying $post. The value of @messages isn't touched during the foreach loop because data from the array is copied into the scalar.

That said, I see a change in performance as well when I use local to create a copy of @messages, and I just don't get it.

  • Comment on Re: Re: Strange benchmark result that has me totally confounded

Replies are listed 'Best First'.
Re: Re: Re: Strange benchmark result that has me totally confounded
by chromatic (Archbishop) on Apr 16, 2004 at 19:15 UTC

    As perldoc perlsyn says:

    In other words, the "foreach" loop index variable is an implicit alias for each item in the list that you're looping over.

    I don't think local will do it either; not unless you want an empty array or are doing something a lot more clever than I can imagine. You need to reset the values of the array for each benchmark iteration.

Re: Re: Re: Strange benchmark result that has me totally confounded
by simonm (Vicar) on Apr 16, 2004 at 20:32 UTC
    But I'm not modifying @messages, am I?

    Surprise! You are, due to the magic of variable aliasing:

    my @messages = <DATA>; foreach my $post ( @messages ) { $post =~ s/ /-/g; } print @messages; __DATA__ one foo bar three words here

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://345900]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.