Sui Ming Louie wrote:
>
> Thank you for all the responses and interesting insights.
>
>
>
> After some experimentation, I have come up with the following code snippet
> which pads the first "column" numbers with zeros (0's) instead of white
> spaces:
>
>
>
> if ($section_1_line =~ /^\s*\d+/) {
> my $regex_search ='^\s';
> my $regex_replace = '0';
> for (my $icnt = 1 ; $icnt <= 5 ; ++$icnt) {
> if ($section_1_line =~ /$regex_search\d/) {
> $section_1_line =~ s/$regex_search/$regex_replace/;
> last;
> } else {
> $regex_search .= '\s';
> $regex_replace .= '0';
> } # if
> } # for
> } # if
>
>
>
> This might not be the most elegant way to achieve my goal, but it works for
> now. This also maintains the original file size, which is not that
> important. If anyone can see a better way, please feel free to respond.
That would be neater as
$section_1_line =~ s/^(\s+)/'0' x length $1/e;
HTH,
Rob
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs