[Melbourne-pm] Just how much does $& slow things down?

Leigh Sharpe lsharpe at pacificwireless.com.au
Thu Nov 20 18:42:56 PST 2008


Hi All,
 Can anybody give me an idea of just how much impact using $& can have
on a program?
I have a function which does something like this:
 
foreach my $this_line(@an_array)
{
    next if ($this_line=~m/something which indicates we're not
interested/);        
    if ($this_line =~m/something we are interested in \d*\.*\d*)

    {
        my $foo=$&;
        # Do some stuff with $foo
    }
    elsif ($this_line=~m/something else interesting \d*\.*\d*/)
    {
        my $bar=$&;
        # Do something with $bar
    }
}
 
 
@an_array could be anything up to about 50 elements.
 
This is the only place in the whole program which uses a regex, so the
impact on other parts of the program should be nil.
I just don't know if it's going to be worth removing those references to
$&, and how much it will benefit the running of the program.
Obviously, the bigger @an_array is, the larger the impact, but I can
safely say it won't be much bigger than about 50.
So, are we talking an order of magnitude slower? More? Less? Anybody
even want to take an educated guess?
 
Regards,
             Leigh
 
Leigh Sharpe
Network Systems Engineer
Pacific Wireless
Ph +61 3 9584 8966
Mob 0408 009 502
Helpdesk 1300 300 616
email lsharpe at pacificwireless.com.au
<blocked::mailto:lsharpe at pacificwireless.com.au> 
web www.pacificwireless.com.au
<blocked::http://www.pacificwireless.com.au/> 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20081121/628d89fb/attachment.html>


More information about the Melbourne-pm mailing list