in reply to Pattern Matching

I actually prefer it the way it is. It should be fairly obvious to non-Perl programmers what is going on here, and slamming everything into one line will certainly make some ears blead. However, by grouping things together, you can have a little of both worlds:
$report =~ tr/0-9//d; # numbers $report =~ tr/-_.//d; # underscores, dashes, and periods $report =~ s/crs//ig; # crs, lower or upper $report =~ s/html//g; # filter out the phrase 'html'

Update
Nice catch merlyn. I'll leave that comment untouched, as i had originally tried /_-./ before posting. I should add that i rarely use comments like that anymore as they are maintenance nuisances, IMHO.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
•Re: (jeffa) Re: Pattern Matching
by merlyn (Sage) on Dec 16, 2002 at 17:54 UTC
    $report =~ tr/-_.//d; # underscores, dashes, and periods
    I would yellow-flag that in a code review, since the comment does not precisely match the action, and needlessly. Some maintenance programmer is going to wonder "Why does he call a dash an underscore?".

    I might also add a comment to explain why it's not

    tr/_-.//d
    which would invoke the range-ness of the dash. Or maybe I'd change it to:
    tr/\-_.//d
    to make it clear that the dash doesn't have its dashing nature.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: (jeffa) Re: Pattern Matching
by Popcorn Dave (Abbot) on Dec 16, 2002 at 17:07 UTC
    In the line

    $report =~ tr/-_.//d; # underscores, dashes, and periods

    won't the . match any character and filter it out? Don't you need to escape it, or does it work differently with the tr as opposed to s?

    There is no emoticon for what I'm feeling now.

      No, tr/// is not s/// or m//, but it's y/// :-)

      The transliteration operator does not have anything to do with regular expressions, that's why the . doesn't have special meaning in it. See perlop.

      --
      http://fruiture.de
        Thanks for the clarification!

        There is no emoticon for what I'm feeling now.

Re^2: Pattern Matching
by Aristotle (Chancellor) on Dec 16, 2002 at 20:19 UTC
    Of course that can be condensed a bit:
    $report =~ tr/\-_.0-9//d; $report =~ s/$_//ig for qw(crs html);
    I debated putting the crs and html together in an alternation but I'm relatively certain it'd be a loss so I picked a for to satisfy the once and only once rule.

    Makeshifts last the longest.

Re: (jeffa) Re: Pattern Matching
by Mr. Muskrat (Canon) on Dec 16, 2002 at 16:06 UTC
    You might want to ignore the case with the last substitution as well... many people write it HTML. (: