My simple program works well in the terminal window:
#!/usr/bin/perl -w
use strict;
my $answer;
for ($a = 1; $a <= 100; $a++)
{
for ($b = 1; $b <= 100; $b++)
{
$answer = ($a-$b);
print "$a - $b\t$answer\n";
}
}
Output:
1 - 1 0
1 - 2 -1
1 - 3 -2
1 - 4 -3
1 - 5 -4
[etc...]
However, when I insert some code to write to a file it fails an odd death:
#!/usr/bin/perl -w
use strict;
my $answer;
open(WRITE,"+>/Users/dave/Documents/Programming/Perl/081008mathtables/add.txt")
for ($a = 1; $a <= 100; $a++)
{
for ($b = 1; $b <= 100; $b++)
{
$answer = ($a-$b);
print WRITE "$a - $b\t$answer\n";
}
}
close(WRITE);
Output:
syntax error at
/Users/dave/Documents/Programming/Perl/081008mathtables/index.pl line
6, near "1;"
syntax error at
/Users/dave/Documents/Programming/Perl/081008mathtables/index.pl line
7, near "++)
"
syntax error at
/Users/dave/Documents/Programming/Perl/081008mathtables/index.pl line
9, near "++)
"
syntax error at
/Users/dave/Documents/Programming/Perl/081008mathtables/index.pl line
13, near "}"
Execution of
/Users/dave/Documents/Programming/Perl/081008mathtables/index.pl
aborted due to compilation errors.
My machine's permissions seem to be clean. Sadly, the problem seems
to be syntax errors, in code, that ran fine without the,
saving-to-a-file, hook.
Seeking guidance, please.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/