[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Simple file read, split



I'm getting compilation errors when I try and run script, and I can't see
why. Why do I need defined() ... dosn't "$linein = <ALLTIMES>" return true
or false in the if context?.

THE ERRORS:
# syntax error, near "if $alltimes"
File 'Hard Disk:Desktop Folder:MyScripts:Workgroup:FindTimesThisUser'; Line 31
# Value of <HANDLE> construct can be "0"; test with defined().
File 'Hard Disk:Desktop Folder:MyScripts:Workgroup:FindTimesThisUser'; Line 28
# syntax error, near "}"
File 'Hard Disk:Desktop Folder:MyScripts:Workgroup:FindTimesThisUser'; Line 34
# Execution of Hard Disk:Desktop
Folder:MyScripts:Workgroup:FindTimesThisUser aborted due to compilation
errors.

THE DATA: (script hasn't had chance to look at yet)
john	120299	1030	1230
fred	120499	1600	2000
john	090999	1830	1900
mary	020899	0730	0900

THE SCRIPT:
#!perl -w

############################################
#This script takes input in the form of lines from a file which represent
#records from a database, and finds records which have a particular
#value in the first field of each record. The fields are separated
#by tabs.
#The purpose of the script is to allow the times that a particular
#person will be available at their desk  to be listed
############################################

#The value to lookup
print 'Enter the username: ';
$username = <>;
$username = chomp($username);

#The file with database, and the file to output to
open (ALLTIMES,  '<timeson.txt');
open (FOUNDTIMES, '>found.txt');

#Setup the output file
print FOUNDTIMES '<html>',"\n";
print FOUNDTIMES '<head><title>In Office: ',"$username",'</head>',"\n";
print FOUNDTIMES '<body>',"\n";
print FOUNDTIMES '<table>',"\n";

#Line by line, seperates first field, finds on first field, if a match writes
while ($linein = <ALLTIMES>) {
	chomp($linein);
	@alltimes = split(/\t/,$linein);
	if $alltimes[0] eq $username {
		print
'<tr><td>',$alltimes[1],$alltimes[2],$alltimes[3],'</td></tr>',"\n";
		}
	}

#Setdown the output file
print FOUNDTIMES '</table>',"\n";
print FOUNDTIMES '</html>',"\n";

#Close files
close ALLTIMES;
close FOUNDTIMES;



Cheers ... John






===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org