in reply to Clean Up downloaded "messy" script?

Your specification of 'first 3 characters are whitespaces and/or a number followed by ":"' is a bit conflicting - does that include 3 whitespaces followed by a number? should 3 whitespaces be followed by a colon? - but here's the best match I can come up with for that description (I'm guessing the answer to both of the above is "no"):

#!/usr/bin/perl -w use strict; # Build a regex of "\d\d\d:|\s\d\d:|\s\s\d:|\s\s\s" my $str = join ":|", map { '\s'x$_ . '\d'x(3-$_) } 0 .. 3; while (<>){ s/^$str//; # Remove anything that matches regex from start of line print; }

--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^2: Clean Up downloaded "messy" script?
by matze77 (Friar) on Dec 20, 2008 at 14:52 UTC

    Thought of doing it in 3 cycles (all at the beginning of the line ofc):
    1st: Remove all whitespaces.
    2nd: remove all numbers.
    3rd: remove ":"
    This should not conflict with regular code like #! or leading whitespaces *after* the ":" ...

    Thank you oko1, i learned another method i didnt know ... MH