Just a little note on efficiency...

use Benchmark; sub a { $_ = "this is a\ntest\n"; s/(?:\s+|\n+)//gc; } sub b { $_ = "this is a\ntest\n"; s/\s+//gc; } sub c { $_ = "this is a\ntest\n"; tr/\n\r\t //d; } timethese(250000,{ a => \&a, b => \&b, c => \&c }); Benchmark: timing 250000 iterations of a, b, c... a: 5 wallclock secs ( 4.18 usr + 0.01 sys = 4.19 CPU) @ 59 +665.87/s (n=250000) b: 1 wallclock secs ( 1.61 usr + 0.03 sys = 1.64 CPU) @ 15 +2439.02/s (n=250000) c: 1 wallclock secs ( 0.66 usr + 0.02 sys = 0.68 CPU) @ 36 +7647.06/s (n=250000)
All of these have the same effect on the string...

for one... \s includes \n, so the right part of that doesn't ever actually do anything useful, but I believe it still gets checked each time to make sure it doesn't make a better match... I believe in most cases a character class would be better for that, but that is really irrelevant, since stripping single characters is much faster with tr///d

Just thought I would point it out...

                - Ant
                - Some of my best work - (1 2 3)


In reply to Re: Re: Extracting text after a keyword by suaveant
in thread Extracting text after a keyword by Anonymous Monk

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.