[EMAIL PROTECTED] wrote:
> Using a regex, I want to replace each leading space-character with a
> corresponding zero-character on a one-to-one basis. For an example
> string:
> 
> My $string = '     259.00 ';
> 
> Note that I don't want to change the trailing space character. The
> resulting string would look like:
> 
> '00000259.00 '
> 
> The total length of the string would remain the same after the replace
> operation.
> 
> I'm just having a total brain-fade on this one.
        It was brain fade here also, but finally found one way:

#!perl

use strict;
use warnings;

$_ = '      259.00 ';
print $_ . "\n";

s/^(\s+)/sprintf "%s", q[0]x length($1)/eg;
print $_ . "\n";
Output:
      259.00
000000259.00

        hth

Wags ;)
> 
> Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis
> MO - USA Central Time Zone
> 636-755-2652 fax 636-755-2503
> 
> [EMAIL PROTECTED]
> www.nisc.coop
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to