in reply to substitute leading whitespace

my $string = ' this is a string'; my $rep; $string =~ s/(^\s+)/$rep.=':' for(1..length($1)); "$rep"/eg; print $string;
Something like this will do what you are looking for. Of course there are probably other ways of doing this too but this is the first that comes to my mind.

Replies are listed 'Best First'.
Re^2: substitute leading whitespace
by Anonymous Monk on Jun 11, 2005 at 05:46 UTC
    That for could easily be replaced with the x operator. The /g modifier is useless. The quotes around $rep are useless. In other words, this is a very poor re-implementation of kaif's answer.
      As I stated it is only one way. I also posted this while kaif was posting his/hers so it is not a re-implementation of anything.

      You know it is very easy to compare two solutions and pick them apart to appear smart like so many people on this site tend to do. It awards them upvotes by the regular users of this site who can not see through their stupidity. You should try having an original idea once in a while. I think you will find it liberating. This goes for everyone who has adopted this method of gaining votes to appear intelligent. Who cares about the stupid points. Most of you seem to get confused between fantasy and reality. Status or standing at this single website gives you nothing in life. Try taking a step out and offer a solution instead of offering nothing except contempt. I welcome downvotes from anyone who disagrees, but then again you may have to accpet the fact that you are this type of person who I have outlined above.