matze77 has asked for the wisdom of the Perl Monks concerning the following question:

If i got something like this (code tags forgotten), taken from: "animal":
10: use Data::Dumper; 11: 12: my $info = "dog"; 13: 14: { 15: try($info);

Pseudo Code:

foreach { ("^ ") && | [[0-99]:]; print ""; }

Explanation/Condition: If the first 3 characters of the line are whitespaces and/or a number followed by":" do replace whitespace and numbers by "" empty string?

Now the question is: How do i have to use awk and sed e.g. or what would you suggest is effective to accomplish this?.

Sure i could delete it all manually but since this is a common stupid problem and i need to practice my poor "skills" ...

"Disclaimer: The word "messy" is only meant in context of the formatting if copied not regarding the content"

Update: solved, done in bash/shell again:
sed s/^[ \t]*// #remove leading whitespaces sed s/^[0-9]*//g #remove leading numbers sed s/^:*//g #remove leading ":"
Thx Corion
/update:

Thanks in Advance
MH

Replies are listed 'Best First'.
Re: Clean Up downloaded "messy" script?
by Corion (Patriarch) on Dec 20, 2008 at 13:45 UTC

    How about using the s/// operator (which you could know from sed)?

    s/^\s*\d+://;

    or, in a oneliner:

    perl -lpe "s/^\s*\d+://;"

    or run the following to get a full Perl script that does the cleanup:

    perl -MO=Deparse -lpe "s/^\s*\d+://;"
Re: Clean Up downloaded "messy" script?
by oko1 (Deacon) on Dec 20, 2008 at 14:22 UTC

    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

      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