Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi all i am new to perl just trying to figure out how I would format my output to look a certain way if possible. I want it be in 3 columns 10 rows Avery 5160 format, but without the use of PostScript. but right now it only show all in one column all the way down.
#!/usr/bin/perl # Program name: perlReadAndFormat.pl # Purpose: Open disk file. Read and display the records in # the file. Count the number of records in the file. format LABEL = @<<<<<<<<<<<<<<<< $CUSTID @<<<<<<<<<<<<<<<< $fname @<<<<<<<<<<<<<<<< $lname @<<<<<<<<<<<<<<<< $phone @<<<<<<<<<<<<<<<< $address @<<<<<<<<<<<<<<<< $city @<<<<<<<<<<<<<<<< $state @<<<<<<<<<<<<<<<< $zip @<<<<<<<<<<<<<<<< $email . #$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); # required terminator for format definition open (FILEIN, "cust.txt") || warn "Could not open passwd file\n"; open (LABEL, ">labels-to-print") || warn "Can't create labels file\n"; while (<FILEIN>) { #print "$_"; ($CUSTID,$fname,$lname,$phone,$address,$city,$state,$zip,$email) += split(/,/,$_); # Or use array: @fields = split(/,/,$_); write(LABEL); # send to output ++$line_count; } print ("File \"passwd\" has $line_count lines. \n"); close (FILEIN); close (LABEL);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl formatting beginner
by ww (Archbishop) on Apr 15, 2014 at 16:06 UTC | |
by Tux (Canon) on Apr 15, 2014 at 18:00 UTC | |
by 2teez (Vicar) on Apr 15, 2014 at 18:07 UTC | |
|
Re: Perl formatting beginner
by Not_a_Number (Prior) on Apr 15, 2014 at 20:56 UTC | |
|
Re: Perl formatting beginner
by DrHyde (Prior) on Apr 16, 2014 at 10:30 UTC | |
|
Re: Perl formatting beginner
by RonW (Parson) on Apr 16, 2014 at 17:18 UTC | |
|
Re: Perl formatting beginner
by Not_a_Number (Prior) on Apr 15, 2014 at 20:51 UTC | |
by Anonymous Monk on Apr 15, 2014 at 21:00 UTC | |
by ww (Archbishop) on Apr 15, 2014 at 23:40 UTC |