On Jun 29, Timothy said:

>I'm sure this is a really easy question but here goes. I'd like to replace
>each leading blank of a string with   I have currently:
>
>               $strLine =~ s/^\s+/ /g;

That /g is pointless there...

>I can see that this will simply take all leading blanks and replace them
>with one   but how do I get *each* leading blank to be replaced with
>a  ? TIA:) 

You could take the Randal Schwartz approach:

  $strLine =~ s/\G\s/ /g;

or you could take the backreference approach:

  $strLine =~ s/^(\s+)/' ' x length($1)/e;

That first one replaces a space with ' ', as long as it was found
right after the last one.  The second one replaces all leading spaces with
' ' repeated as many times as necessary.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to