in reply to Perl formatting beginner

First:

#$topmargin = 0.60; #$poleft = 0.4; $pomiddle = 3.20; $poright = 5.95; $lheight = 1; $row = int($opt{r}) || 1; # chop off any fractional parts and $col = int($opt{c}) || 1; if ($col == 1) { $po = $poleft; } elsif ($col == 2) { $po = $pomiddle; } else { $po = $poright; } # $sp = ($topmargin + ($row - 1)*$lheight);

I have no idea what these 16 lines are meant to do. I doubt that you have, either, since none of the variables defined are actually used...

Second:

I can only agree with ww that:

IT WOULD HAVE BEEN NICE IF YOU'D SHOWN US THE DESIRED OUTPUT!

However, for the sake of argument, let's presume that you'd like the following output from ww's __DATA__ section:

1 fred jones 555-1212 123 Main St. Boston MA 00001 test@test.com 2 mary smith 222-1515 321 Least St. Hanover NH 02022 testmary@test.com 3 jack least 122-5511 231 Last St. Franklin CT 06001 nomail@test.com

In that case, you need to change your format definition to something like:

@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< $CUSTID,$fname,$lname @<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< $phone,$address,$city @<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< $state,$zip,$email

Proof of concept:

use strict; use warnings; my @fields; format = @<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< @fields[ 0 .. 2 ] @<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< @fields[ 3 .. 5 ] @<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<< @fields[ 6 .. 8 ] . while ( <DATA> ) { @fields = split /,/; write; } __DATA__ 1,fred,jones,555-1212,123 Main St.,Boston,MA,00001,test@test.com 2,mary,smith,222-1515,321 Least St.,Hanover,NH,02022,testmary@test.com 3,jack,least,122-5511,231 Last St.,Franklin,CT,06001,nomail@test.com

Third:

Don't use format. It's just too clunky. Learn how to use printf/sprintf:

use strict; use warnings; while ( <DATA> ) { my @fields = split /,/; while ( my @chunk = splice @fields, 0, 3 ) { printf "%-17s", $_ for @chunk; print "\n"; } } __DATA__ 1,fred,jones,555-1212,123 Main St.,Boston,MA,00001,test@test.com 2,mary,smith,222-1515,321 Least St.,Hanover,NH,02022,testmary@test.com 3,jack,least,122-5511,231 Last St.,Franklin,CT,06001,nomail@test.com

Fourth:

Other respondents are right: use Text::CSV rather than naïvely splitting the lines from your input file on commas.

Update:

Combined internet connection/brainfart problems have necessitated several unlisted alterations to the original version of this post. My apologies.