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/

In reply to (jjhorner)Regexp glitch while parsing record in CSV by jjhorner
in thread Regexp glitch while parsing record in CSV by greenhorn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.