1. Perl is indeed wonderfully capable... but do you really need to do it the hard way? After all, a standard Perl remark is 'don't reinvent the wheel:' http://office.microsoft.com/en-us/templates/avery-5160-mailing-labels-featuring-avery-app-for-word-2013-anniversary-design-30-per-page-TC103749911.aspx
  2. But if you're still going to do it in Perl, it looks as though you have a comma-delimited source file, AKA, CSV. So use one of the csv modules to drag in your data (not that what you were doing is terribly wrong).
  3. And if you're still going to do it your way -- minus the formatting:
#!/usr/bin/perl use strict; use warning; #mandatory inclusions until you know enough to know +when you can skip these helpers use 5.016; # Program name: perlReadAndFormat.pl # Purpose: Open disk file. Read and display the records in # the file. Count the number of records in the file. # open (FILEIN, "cust.txt") || warn "Could not open source file\n"; open (LABEL, ">","labels-to-print.txt") || warn "Can't create labels f +ile\n"; # while (<FILEIN>) while (<DATA>){ #print "$_"; ($CUSTID,$fname,$lname,$phone,$address,$city,$state,$zip,$email) += split(/,/,$_); # Or use array: @fields = split(/,/,$_); # write(LABEL); # send to output print LABEL "$CUSTID,$fname,$lname\n$address,$city,$state,$zip\n$ +phone,$email\n"; ++$line_count; } print ("File \"passwd\" has $line_count lines. \n"); close (FILEIN); close (LABEL); __DATA__ $CUSTID,$fname,$lname,$phone,$address,$city,$state,$zip,$email 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

Output:

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

Obviously, this ignores your desire to spread them over the page; that's left as an exercise...
BUT IT WOULD HAVE BEEN NICE IF YOU'D SHOWN US THE DESIRED OUTPUT!


Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
  1. code
  2. verbatim error and/or warning messages
  3. a coherent explanation of what "doesn't work actually means.

check Ln42!


In reply to Re: Perl formatting beginner by ww
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.