On Oct 21, 2005, at 8:39, Beast wrote:

#!/usr/bin/perl
use strict;

my $log = '/non/existence/dir/test.log';
my $msg = "test";
&write_log($msg);

sub write_log {
   my $msg = shift;
   open LOG, ">>$log" || die "Can't write to $log: $!\n";

This is a gotcha, it is parsed like this:

    open LOG, (">>$log" || die "Can't write to $log: $!\n");

To write it as you want either use parens in the open call:

    open(LOG, ">>$log") || die "Can't write to $log: $!\n";

or switch to the "or" operator, which is the usual idiom:

    open LOG, ">>$log" or die "Can't write to $log: $!\n";

The precedence of "or" is defined in a way that makes those kind of constructs behave as you expect.

-- fxn

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to