in reply to Remove leading spaces (left justify)

$s =~ s[^ +][]mg;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Remove leading spaces (left justify)
by eyepopslikeamosquito (Archbishop) on May 17, 2003 at 05:50 UTC

    That unilaterally removes all leading spaces. I want to maintain any relative indentation. For example:

    hello one two

    should be transformed to:

    hello one two

    i.e. remove two spaces from each line in this case because the minimum number of leading spaces in any line is two. Sorry if I was unclear.

      Sorry. I misunderstood you. This would do it.

      $s =~ s[^ ][]mg while not $s =~ m[^[^ ]]mg;

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
        Very concsie, but gets very slow for big strings with lots of space, as it will loop through the entire string once for each leading space it removes.

        Bob Niederman, http://bob-n.com