in reply to Re: Sub Return Value Help
in thread Sub Return Value Help
Do not use bare word filehandles.Bare word filehandles have worked fine since perl1.000, where the way 99% of the code used filehandles until 5.6.0, and are still used in the majority of the code.
Just stating "don't use bare word filehandles" without any motivation at all doesn't serve anybody.
use the three argument form of open: open(my $fh, '<', $file)Again, no motivation why to not use a construct which has worked fine for almost 20 years. Just because there's a different way of doing things isn't reason enough to critize the old use.
If you are doing an exact match... perhaps you want to use substr instead of a regex. (Would be much faster).Really? How about this benchmark:
use Benchmark 'cmpthese'; our $orig = "a" x 20; $orig .= "<!-- TBROWS //-->"; $orig .= "a" x 20; $orig .= "<!-- TBROWS //-->"; $orig .= "a" x 20; cmpthese(-1, { 's///' => 'my $c = $orig; $c =~ {<!-- TBROWS //-->}{XXXX}g;', substr => 'my $c = $orig; while ((my $i = index($c, "<!-- TBROWS //-->")) > -1 +) { substr($c, $i, 17) = "XXXX"; }' }); __END__ Rate substr s/// substr 240498/s -- -37% s/// 381869/s 59% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sub Return Value Help
by JediWizard (Deacon) on Aug 01, 2005 at 17:36 UTC | |
|
Re^3: Sub Return Value Help
by JediWizard (Deacon) on Aug 01, 2005 at 17:30 UTC | |
by gellyfish (Monsignor) on Aug 01, 2005 at 17:58 UTC | |
by JediWizard (Deacon) on Aug 01, 2005 at 18:20 UTC | |
by gellyfish (Monsignor) on Aug 01, 2005 at 18:46 UTC | |
by JediWizard (Deacon) on Aug 01, 2005 at 23:03 UTC | |
|