I'm confused.

tachyon posted an interesting solution, but i can't makes any sense of it.

first of all, i could find no mention of /c in perlman:perlre, but perl didn't barf on it -- so what does it do?

second, i tried the following near-identical code and it didn't do at all what i expected:
#!/usr/bin/perl -w use strict; my $string = "foo bar baz bar quux foo gin"; my @list = qw(foo bar); $string =~ m/\Q$_\E/gc for @list; my ($rest) = $string =~ m/\G(.*)$/; print "$rest\n";
.. it printed:
foo bar baz bar quux foo gin
and honestly, i can't see how it could possibly work the way you wanted it to. it seems to me that the /g on the m// would cause the 'foo' to match at the first and sixth words, and then the 'bar' to match at words 2 and 4, leaving the \G assertion after word 4, not after word 2 where i think it belongs.

obviously, i'm missing some of what's going on here. can you enlighten me?


In reply to Re: Re: getting the first n printable words from a string of HTML by Vynce
in thread getting the first n printable words from a string of HTML 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.