in reply to Regexp glitch while parsing record in CSV
I'm not getting the same results as everyone else:
#!/usr/bin/perl -w use strict; use Benchmark; my $string = " field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 "; sub regexp { $string =~ m#^(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*),(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*),(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*),(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*),(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*),(\s*)(\w*?)(\s*), (\s*)(\w*?)(\s*)$#o; my $s = $11; print $s; } sub splitter { my $s = (split(/\s*,\s*/, $string))[3]; print $s; }
Yields:
[22:31:17] Orders, Master? ./greenhorn-0716.pl Benchmark: timing 100000 iterations of regexpression, splitting... regexpression: 12 wallclock secs (12.78 usr + 0.00 sys = 12.78 CPU) @ + 7824.73/s (n=100000) splitting: 8 wallclock secs ( 7.90 usr + 0.00 sys = 7.90 CPU) @ 12 +658.23/s (n=100000)
Is there something wrong with my code? I know that isn't the best regular expression ever created, but I would like to know why it doesn't beat the split.
Note: To whomever I saw with the shell prompt like I have above, that is so cool!
J. J. Horner Linux, Perl, Apache, Stronghold, Unix jhorner@knoxlug.org http://www.knoxlug.org/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(chromatic) RE: (jjhorner)Regexp glitch while parsing record in CSV
by chromatic (Archbishop) on Jul 17, 2000 at 07:57 UTC |