Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password

Programming > Perl Beginners > Substitute Vari...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 12 Topic 10952 of 11948
Post > Topic >>

Substitute Variably hort string into long string at Right Justified

by pgn674@[EMAIL PROTECTED] (Paul Nickerson) Apr 17, 2008 at 01:14 AM

In short, I'm looking to do this: integer 4 -> string dbt0004sfg, and
integer 287 -> string dbt0287sfg.

And now in long, I want to iterate through creating strings to print
the bellow:
dbt0001sfg
dbt0002sfg
....
dbt0034sfg
....
dbt2601sfg
....

I think what I'm looking for is a regular expression to take a string
of some arbitrary length, and substitute it into a longer string at a
constant, right justified position. I can calculate the left justified
position if necessary, using integer division or grabbing the length
of the first string. I'm familiar with several languages, and have
been programming for some time now, but I'm still a beginner for Perl
specifically. Below I have some skeleton code that I think will work
for me, once I figure out the magic.

for($i=1; $i<=9999; $i++)

{

	$longer = "dbt0000sfg";

	$iChar = sprintf("%u", $i);

	#  Magical regular expression stuff happens. #

	print "$longer\n";

}

So, anyone know if there's an elegant way to do this with regular
expressions? I know I can do it with a bunch of if-then statements,
but that's ugly, plus I think I may ultimately be doing this on 7 or
more digits (I won't be changing how long each output needs to be
midway through the program, don't worry).

I've been going over regular expression intro's, and Googling for this
specifically, but I haven't come across anything yet.
 



 12 Posts in Topic:
Substitute Variably hort string into long string at Right Justif
pgn674@[EMAIL PROTECTED]   2008-04-17 01:14:31 
Re: Substitute Variably hort string into long string at Right Ju
chas.owens@[EMAIL PROTECT  2008-04-17 07:48:18 
Re: Substitute Variably hort string into long string at Right Ju
Jenda@[EMAIL PROTECTED]   2008-04-17 15:07:51 
Re: Substitute Variably hort string into long string at Right
pgn674@[EMAIL PROTECTED]   2008-04-17 16:51:10 
Re: Substitute Variably hort string into long string at Right Ju
rob.dixon@[EMAIL PROTECTE  2008-04-18 18:38:32 
Re: Substitute Variably hort string into long string at Right Ju
chas.owens@[EMAIL PROTECT  2008-04-19 13:12:16 
Re: Substitute Variably hort string into long string at Right Ju
rob.dixon@[EMAIL PROTECTE  2008-04-19 18:57:16 
Re: Substitute Variably hort string into long string at Right Ju
rob.dixon@[EMAIL PROTECTE  2008-04-19 18:03:45 
Re: Substitute Variably hort string into long string at Right
Uri Guttman <uri@[EMAI  2008-04-19 17:49:16 
Re: Substitute Variably hort string into long string at Right Ju
chas.owens@[EMAIL PROTECT  2008-04-19 14:53:06 
Re: Substitute Variably hort string into long string at Right Ju
rob.dixon@[EMAIL PROTECTE  2008-04-20 12:38:03 
Re: Substitute Variably hort string into long string at Right Ju
chas.owens@[EMAIL PROTECT  2008-04-20 10:18:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 7 16:25:54 CDT 2008.