Need some help with Perl

Jamie Dobbs jamie.dobbs at paradise.net.nz
Tue Oct 30 10:46:42 NZDT 2001


Sorry about the length of this email but all the code is necessary so
people can see what I'm doing (Its my first Perl program so please
don't hassle my 'style' (or lack thereof!) too much)

OK, I have the following code:

!/usr/local/bin/perl
#This program will process 'run-on' type racing fields

use Shell;

$file = $ARGV[0]; #get the file passed as the command line
parameter
open(INFO,$file);	#open the file
@lines=<INFO>;	#read the contents of the file into an array
close(INFO);	#close the file

#Set up the 'hash table' for the race venues
%venues = ( roto => "Rotorua",
mlbh => "Marlborough",
wavE => "Waverly",
otag => "Otago",
wint => "Winton",
wodv => "Woodville",
wynd => "Wyndham" );

#process the 'array'
$venue = substr $file,4,4;
$date = (substr $file,0,2).("/").(substr $file,2,2);
$day = date("-d ", $date," +%a");
$day = substr $day,0,3;
#create the 'header' information
$newlines = "";
$newlines = $newlines.chr(1)."R RBT FIELDS".chr(19).chr(18).chr(2);
$newlines = $newlines.chr(9)."$venues{$venue}-$day-FIELDS"; 
$newlines = $newlines.chr(9)."$venues{$venue} $day FIELDS"."\n"; 
#now process each line of the input array and add it to the newlines
array for sending
foreach $line (@lines)	#visit each line in turn and call it $line
{
$lines =~ s/\n//g;
$lines =~ s/\r//g;
$lines =~ s/cM//g;
#if the line starts with RACE put a blank line before it
if ($line =~ /^ RACE/)
{
$newlines = $newlines." \n\t".$line;
}
#if the line ends with , or ) print it with a trailing space
elsif ($line =~ /,$/ | $line =~ /\)$/)
{
$newlines = $newlines.$line." ";
}
#if the line starts with a digit print it with a leading TAB
elsif ($line =~ /^ \d/)
{
$newlines = $newlines."\t".$line;
}
#if the line starts with a non alphanumeric character print
it with a
#leading TAB (eg. race purse figure has $ at start)
#also set flag to indicate next section is runon copy
elsif ($line =~ /^ \W/)
{
$newlines = $newlines."\t".$line;
$flag = "\t";
}
#if the word TAB appears preceed it with a TAB character
elsif ($line =~ /^ TAB/)
{
$newlines = $newlines."\t".$line;
}
#if none of the above then print it without a TAB in front
else
{
$newlines = $newlines.$flag.$line;
$flag = "";
}
}
$newlines = $newlines."\nNZPA WGT".chr(4);
#Now output the processed array to a file ready to send to Tandem
$ofile = "$file".".txt";	#create a new file with a .txt
extension
open(INFO,">$ofile");	#open the file for output
print INFO $newlines;	#output the new 'array' to the file
close(INFO);

It processes the input file fine and puts it into a file once all the
'modifications' have been done. The problem is though that the output
files has an 0D 0D 0A sequence at the end of everyline which makes it
appear double line spaced when I send it to our mainframe.
Can anyone help me out and give me a method whereby I can remove the
extra line between each line output?

TIA

Jamie

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.291 / Virus Database: 156 - Release Date: 25/10/2001



More information about the wellylug mailing list