in reply to Re: Question of variable interpolation in regex
in thread Question of variable interpolation in regex
Is this what you were looking for? The same number of spaces that were previously '.'s on the line?#!/usr/local/bin/perl -wT use strict; my($putNum,$line,$s_count,$num,$n_line, @square); $putNum = 1; @square = ( '+----+', '|....|', '|....|', '|....|', '+----+' ); foreach $line (@square) { if (!$putNum) { $line =~ s/\./ /g; } else { if ($line =~ /\./) { $s_count = $line =~ s/\./\./g; $num++ if ($s_count); $n_line = "$num" . ' ' x ($s_count - length($num)); $line =~ s/\.+/$n_line/o; } } print "$line\n"; } # OUTPUT +----+ |1 | |2 | |3 | +----+
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Question of variable interpolation in regex
by SparkeyG (Curate) on Nov 15, 2002 at 19:48 UTC |