in reply to From one beginner to others . . .
You might want to consider using Benchmark to figure out what works best. I looked at your regex and realized that after you added the capturing parens and assigned the $digit variables, you were looking at a significant performance hit. You can use Benchmark to analyze these things a bit more carefully.
This produced:#!/usr/bin/perl -w use strict; use Benchmark; use vars qw($myvar @results $a $b $c $d); $myvar = "one,two,three,four"; timethese(1000000, { Regex => '($a=$1, $b=$2, $c=$3, $d=$4) if $myvar =~ /^([^,]+),([ +^,]+),([^,]+),([^,]+)$/', Split => '@results = split /,/, $myvar' });
In this case, split was clearly the winner. I'd be interested in seeing some sample data and a code snippet to see how you're getting a regex to outperform a split. The structure of the data is everything when it comes to crafting an efficient regex.Benchmark: timing 1000000 iterations of Regex, Split... Regex: 27 wallclock secs (28.06 usr + 0.00 sys = 28.06 CPU) Split: 16 wallclock secs (16.19 usr + 0.00 sys = 16.19 CPU)
Cheers,
Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: From one beginner to others . . .
by greenhorn (Sexton) on Jul 16, 2000 at 01:54 UTC | |
by frankus (Priest) on Jul 18, 2000 at 17:55 UTC | |
|
RE: RE: From one beginner to others . . .
by greenhorn (Sexton) on Jul 16, 2000 at 02:08 UTC | |
|
RE: RE: From one beginner to others . . .
by greenhorn (Sexton) on Jul 15, 2000 at 22:22 UTC | |
by Ovid (Cardinal) on Jul 16, 2000 at 00:10 UTC | |
by Abigail (Deacon) on Jul 16, 2000 at 01:08 UTC | |
by Ovid (Cardinal) on Jul 16, 2000 at 04:08 UTC |