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.


In reply to Re: Perl formatting beginner by Not_a_Number
in thread Perl formatting beginner by Anonymous Monk

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.