Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Question of variable interpolation in regex

by l2kashe (Deacon)
on Nov 15, 2002 at 19:27 UTC ( [id://213243]=note: print w/replies, xml ) Need Help??


in reply to Re: Question of variable interpolation in regex
in thread Question of variable interpolation in regex

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 */

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
    I solved the 1st problem you rose when $putNum is decided. If the line being considered is either the top or bottom line, $putNum is false.

    As to your second point, tmtowtdi. ;-)

    But I see I still haven't been clear. :-(
    the output I'm seeing is

    +----+----+----+----+ |1 |1 |1 |1 | | | | | | | | | | | +----+----+----+----+
    When what I want is
    +----+----+----+----+ |1 |2 |3 |4 | | | | | | | | | | | +----+----+----+----+
    Update:
    Take a look at my scratch pad for the full code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://213243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found