in reply to Re^2: Best way(s) to process form data into fixed-length values?
in thread Best way(s) to process form data into fixed-length values?
Assuming an example where odd fields are 5 chars long and evens 15:
See the sprintf documentation (pg 797 of Programming Perl 3rd e) for other formats if you need to deal with formatting numerics.my $var1, $var2, $var3, $var4, $var5; #hopefully you'll be using some +meaningful names instead my $format = "%5s%15s%5s%15s%5s\n"; #you could embed spaces in the for +mat specifier too if needed #check/process inputs here #.... $outputline = sprintf $format, $var1, $var2, $var3, $var4, $var5;
You can break the format statement up or use repeat specifications too so you don't lose count:
(Though the former is likely to be unwieldy when the client changes the content three times a day)my $format = "%5s%5s%5s%5s%5s"."%5s%5s%5s%5s%5s"."%5s%5s%5s%5s%5s". "%5s%5s%5s%5s%5s"."%5s%5s%5s%5s%5s"."%5s%5s%5s%5s%5s". "%5s%5s%5s%5s%5s"."%5s%5s%5s%5s%5s"; my $otherformat" = "%5s"x40;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Best way(s) to process form data into fixed-length values?
by GrandFather (Saint) on Jul 26, 2006 at 04:16 UTC |