Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Here's a variation for 5.8 and also for 5.10 that's simpler (for some definition of 'simpler') and that I think should run faster since it avoids  /e code evaluation during replacement, but again, I've done no benchmarking. Of course, the same approach applies as well to the 5.14 version code. Tested with the same Perl versions/vendors as before. Also to repeat: adding more of your own test cases would probably be a good idea.

# should be ok for any version 5.8.9+ sub replace_5_8_9_b { my ($string, ) = @_; my $rx_dquot = qr{ " [^"]* (?: "" [^"]* )* " }xms; my $rx_ceol = qr{ ' [^\n]* \n? \z }xms; my $rx_skipem = qr{ $rx_ceol | $rx_dquot }xms; # alt order immate +rial # my $rx_skipem = qr{ $rx_dquot | $rx_ceol }xms; # alt order immate +rial my $rx_keepit = qr{ (?! $rx_rename) (?! $rx_dquot) (?! $rx_ceol) . + }xms; $string =~ s{ \G ((?: (?> $rx_keepit*) | (?> $rx_skipem*))*) # skip this stuff ($rx_rename) # grab and rename } {$1$renames->{$2}}xmsg; return $string; } # uses \K and possessive quantifiers from 5.10+ sub replace_5_10_1_b { my ($string, ) = @_; my $rx_dquot = qr{ " [^"]*+ (?: "" [^"]*+ )*+ " }xms; my $rx_ceol = qr{ ' [^\n]*+ \n?+ \z }xms; my $rx_skipem = qr{ $rx_ceol | $rx_dquot }xms; # alt order immate +rial # my $rx_skipem = qr{ $rx_dquot | $rx_ceol }xms; # alt order immate +rial my $rx_keepit = qr{ (?! $rx_rename) (?! $rx_dquot) (?! $rx_ceol) . + }xms; $string =~ s{ \G (?: $rx_keepit*+ | $rx_skipem*+)* # skip this stuff \K ($rx_rename) # grab and rename } {$renames->{$1}}xmsg; return $string; }

In reply to Re: Replacing words in VB code but not strings or comments (Simplified versions) by AnomalousMonk
in thread Replacing words in VB code but not strings or comments 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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2014-12-21 00:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (100 votes), past polls