Gossamer Forum
Home : General : Perl Programming :

Precedence

Quote Reply
Precedence
I could have sworn this code used to work...

Code:
my $href = do($path) or return $self->fatal("Oops: $!");

But now if do() returns false nothing happens. In order for the error to trigger I have to use:

Code:
my $href = do($path) || return $self->fatal("Oops: $!");

I'm guessing I could also write that as:

Code:
(my $href = do($path)) or return $self->fatal("Oops: $!");
Quote Reply
Re: [Paul] Precedence In reply to
Mm that's a no for the third example Unsure
Quote Reply
Re: [Paul] Precedence In reply to
1 and 3 are the same. (unless precedence has changed at all in versions > 5.6)

if do($path) returns 0 in both, the result should be the same, since my $href = do($path) will be 0 in the first example.

have you tested with 0 in place of do($path), or printed do($path) to STDOUT?

i'm curious to know what you found...
Quote Reply
Re: [adrockjames] Precedence In reply to
Good idea. I'll try that out tommorrow. I always thought do(0 would return 0 or undef on failure but I guess the best way is to test.
Quote Reply
Re: [adrockjames] Precedence In reply to
Quote:
[root@cypress cgi-bin]# perl -e "print defined(do('/path/to/nothing')) ? 'YES' : 'NO'"

NO[/code]
Surely that means the first example should work? :(

Last edited by:

Paul: Jun 1, 2003, 5:14 PM
Quote Reply
Re: [Paul] Precedence In reply to
The first one does work:

Code:
[alex@penguin projects]$ perl -le 'my $href = do("/abc") or return $self->fatal("Oops: $!");'
Can't call method "fatal" on an undefined value at -e line 1.
[alex@penguin projects]$

(It tried to run ->fatal). Must be something wrong somewhere else (perhaps inside of fatal?)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Precedence In reply to
Mmm that's weird, I've tried it a few times and it won't trigger. As soon as I change "or" to || it then triggers.

The fatal() method is:

Code:
sub fatal {
#----------------------------------------------------------
# Generic error routine. Halts script execution.
# Usage: $class->fatal($error, @vars);

my ($self, $error, @args) = @_;
my ($class, $file, $line) = caller;

# Now grab the error message.
if (ref $error eq 'SCALAR') { $err_msg = $$error }
else {
my $errors = ref ${$class . '::ERRORS'} eq 'HASH' ? ${$class . '::ERRORS'} : {};
if (exists $errors->{$error}) {
$err_msg = sprintf($errors->{$error}, @args);
}
}

# Print the error with extra debugging if debugging is on.
print qq{Content-type: text/html\n\n};
print qq{<font face="tahoma" size="2">An error occured:<br><br>};
print qq{@{[qq{&nbsp;} x 10]}$class ($$): $err_msg<br><br>};
print qq{Caller: $class in $file at line $line};
print qq{</font>};
exit 1;
}
Quote Reply
Re: [Paul] Precedence In reply to
What's in $path? Does it not exist, exist but return false, exist and return true, permission denied?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Precedence In reply to
It doesn't exist.
Quote Reply
Re: [Alex] Precedence In reply to
I'm not sure what's going on but I think its working now. It definitely wasn't working before :(