in reply to Perl formatting beginner
#!/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!
check Ln42!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl formatting beginner
by Tux (Canon) on Apr 15, 2014 at 18:00 UTC | |
by 2teez (Vicar) on Apr 15, 2014 at 18:07 UTC |