Ok I saw a couple of things..

1) In your code you incremented your value even though the first line doesnt match "/\./". So you always start at 2 instead of 1.
2) you were using sprintf for your output when perl already had what you wanted to do built in via the nifty 'x' operator...

I also changed the var names, just cause I could :)
So here is what I came up with
#!/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 | +----+
Is this what you were looking for? The same number of spaces that were previously '.'s on the line?

Happy Hackin :)

/* And the Creator, against his better judgement, wrote man.c */

In reply to Re: Re: Question of variable interpolation in regex by l2kashe
in thread Question of variable interpolation in regex by SparkeyG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.