#!/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 file\n"; # while () while (){ #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 #### 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