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
You could just as easily write that as:
if (/^\s*\d+/) {
s{^(\s+)}{($_ = $1) =~ tr/ /0/; $_}e;
}
or
if (/^\s*\d+/) {
1 while s/^(\s*)\s(\d)/${1}0$2/;
}
or even
s{^(\s+)}{($_ = $1) =~ tr/ /0/; $_}e if /^\s*\d+/;
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs