in reply to editing files with (<>)

The other answer is correct. Just a hint that s/^.*$//; can be (in most cases) easily replaced by $_="\n" and a second hint: Try to negate your "if" and see what happens if you drop the whole "else"-part.

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

Replies are listed 'Best First'.
Re^2: editing files with (<>)
by tbone1 (Monsignor) on Dec 21, 2004 at 15:04 UTC
    Can it? I think that  /^.*$/ will match a string that does not contain a newline, because of the '^' and '$' anchors. If I'm right, and given the cold medicine I'm taking that is certainly no given, any line with a '\n' will not match the regular expression. As $_ is being read from a file, they all will contain a newline. I think. Ugh, more sudafed, please.

    That said, people are right in pointing out that that part of the if clause can be eliminated since it is changing data then doing nothing with it. If nothing else, it should speed up the code.

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee