[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [MacPerl] Simple file read, split
On Mon, Jun 07, 1999 at 10:54:30AM +1000, Peta Adams / John Murray wrote:
> 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?.
All expressions return true or false in a boolean context. That is, after
all, the nature of boolean contexts. The question is when the expression
is true, and when it is false. In this case, $linein = <ALLTIMES> is false
if the line happens to be '0' (the character zero). But you don't want
that to be false, because the input was successful. So test with defined()
instead:
if (defined ($linein = <ALLTIMES>)) {
Note that the defined() is done automatically in perl5.005.
> 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 file with database, and the file to output to
> open (ALLTIMES, '<timeson.txt');
> open (FOUNDTIMES, '>found.txt');
Always check the result of your open()s!
> if $alltimes[0] eq $username {
I'll let you figure this one out for yourself.
Ronald
===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org