perlfaq

 view release on metacpan or  search on metacpan

lib/perlfaq6.pod  view on Meta::CPAN


For example, this program detects duplicate words, even when they span
line breaks (but not paragraph ones). For this example, we don't need
C</s> because we aren't using dot in a regular expression that we want
to cross line boundaries. Neither do we need C</m> because we don't
want caret or dollar to match at any point inside the record next
to newlines. But it's imperative that $/ be set to something other
than the default, or else we won't actually ever have a multiline
record read in.

    $/ = '';          # read in whole paragraph, not just one line
    while ( <> ) {
        while ( /\b([\w'-]+)(\s+\g1)+\b/gi ) {     # word starts alpha
            print "Duplicate $1 at paragraph $.\n";
        }
    }

Here's some code that finds sentences that begin with "From " (which would
be mangled by many mailers):

    $/ = '';          # read in whole paragraph, not just one line
    while ( <> ) {
        while ( /^From /gm ) { # /m makes ^ match next to \n
        print "leading From in paragraph $.\n";
        }
    }

Here's code that finds everything between START and END in a paragraph:

    undef $/;          # read in whole file, not just one line or paragraph
    while ( <> ) {



( run in 0.253 second using v1.01-cache-2.11-cpan-3b35f9de6a3 )