http://qs321.pair.com?node_id=351465

Theo has asked for the wisdom of the Perl Monks concerning the following question:

This is the second Perl script I've done from scratch and I'm havin' a ball! I'd like some constructive criticism over all and in two specific areas.

The objective is to convert an MS Word document of the company phone list to an MS Excel spreadsheet for sorting and conversion to several web pages (of differing sort orders).

The Word file is saved to a text file where each person's info is spread over 3 lines. The script pulls everything into one line per person with tabs separating each item. Having been hand entered, the data is somewhat "dirty". Most of the regexp work is cleaning linefeeds, carriage returns and the random non word characters around the valid data.

Question 1: Is there a more perlish way to count the three lines per person? (What I'm doing looks so much like C.)

Question 2: If you look at the input data for "Bo Jo Le Much" you'll see there is no space after the comma separator and there is a CR (^M) after the first name in the output. If I insert a space after the comma in the input data, the CR in the output goes away. Why?

#!/opt/bin/perl #perl 5.8.3 built for sun4-solaris-64int-ld use warnings; use strict; my $T = "\t"; my $fname = "U1"; my $lname = "U2"; my $phone = "U3"; my $room = "U4"; my $bldg = "U5"; my $email = "U6"; my $temp = "Ut"; my $count = 0; print "\nLast First Phone Bldg Room email\n"; open FH => "<testdata.txt" or die "can't find the data file: $!\n"; #open FH => "<phonedata.txt" or die "can't find the data file: $!\n"; while (<FH>) { chomp; $count++; if ($count == 1){ ($lname, $fname) = split(","); $fname =~ s/^\s+(.+?)\W*$/$1/; }elsif ($count == 2){ ($phone, $temp) = split("/"); #line 28 if ( ($temp =~ m[^\d.*]) || ($temp =~ m[--- --]) ){ ($room, $bldg) = split(" ", $temp); } else { $bldg = $temp; $bldg =~ s/^(.*?)\W*$/$1/; #$bldg includes a 'cr' $room = ""; #no room number, just bldg name } }elsif ($count == 3){ $email = $_; $email =~ s/^(.*?)\W*$/$1/; $count = 0; pA(); }else{ print "Got an overflow - $count $_\n"; } } print "\n" if ($count == 0); close FH; sub pA{print "$lname$T$fname$T$phone$T$bldg$T$room$T$email\n";} ------------------------------------------------------- __Input__ Alanon, Bart 5590/EL ---- O'Lewis, John. ----/--- -- john Le Much,Bo Jo 3406/165 NS ed@a.nl Abe-Jen, Mar-Jo 3421/164D NS cbest __Output__ Last First Phone Bldg Room email Alanon Bart 5590 EL O'Lewis John ---- -- --- john Le Much Bo Jo^M 3406 NS 165 ed@a.nl Abe-Jen Mar-Jo 3421 NS 164D cbest

-Theo-
(so many nodes and so little time ... )