in reply to replacing pipe "|"

When you want to replace all occurrences of a single character with a different single character, use tr/// instead of s///g. It is faster, and you won't ever be bitten by the meta-character problem, because tr/// does not respect meta-characters (no interpolation). Your documentative use of $rem and $rep would need to be replaced by a comment, of course.

# Translate all '|' (pipe) characters into ' ' (spaces). while (<FILE>) { tr/|/ /; print OUTP; }

tr/// is in the perlop manpage. It does a lot more that just single/single transliteration, but this is where tr/// and s/// overlap in function.

FYI, you can do the equivalent under Windows with this one-liner:
perl -pe "tr/|/ /" filename > c:\joshperl\deptemp.txt

Replies are listed 'Best First'.
Re: Re: replacing pipe "|"
by nadadogg (Acolyte) on Mar 27, 2003 at 21:36 UTC
    If it was *always* singles, i would do that, but occasionally i have to change sections. With this one, it is predominantly single-char. Thanks again people