in reply to removing redundantwhitespace

s/[ \t]+/ /g;

Replies are listed 'Best First'.
Re^2: removing redundantwhitespace
by ikegami (Patriarch) on Sep 13, 2008 at 13:19 UTC
    Ug, ignore the parent post. I missed the removal of blank lines and the removal of leading spaces. Here's the straightforward way, when reading from a file:
    while (<$fh>) { chomp; s/^\s+//; next if !length; s/\s+$//; s/\s+/ /g; ... }
      Thanks, but I'm not actually reading from a file. I have this text in a single variable returned from a driver...
        for ($text) { s/^\s+//gm; s/\s+$//gm; s/(\s)\s+/$1/g; }