Re: if statement oddity
From: Brian McCauley (nobull_at_mail.com)
Date: 03/25/05
- Next message: Tad McClellan: "Re: if statement oddity"
- Previous message: Jens Luedicke: "Re: if statement oddity"
- In reply to: Jens Luedicke: "if statement oddity"
- Next in thread: Gunnar Hjalmarsson: "Re: if statement oddity"
- Reply: Gunnar Hjalmarsson: "Re: if statement oddity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Mar 2005 19:34:23 +0000
Jens Luedicke wrote:
> Hiya..
>
> I encountered a strange problem with an if () statement:
>
> if ((my $r = &{$self->{onFile}}($path) != SUCCESS)) {
> return $r;
> }
>
> The above code seems to ignore the return value of the function
> and somehow overrides it. the return value of the called function
> returns FAILED, but $r doesn't reflect that!?
Er? Assuming FAILED != SUCCESS then $r will be set to false. I can't
recell off the top of my head which false but since it immediately goes
out of scope this doesn't matter.
>
> The following code, works as expected:
>
> my $r = &{$self->{onFile}}($path);
>
> if ($r != SUCCESS)) {
> return $r;
> }
No, that contains a syntax error and will not compile.
> fyi, SUCCESS is a constant. use constant SUCCESS => 1;
>
> both code examples should work the same. no matter what!?
>
> do I miss something? I'm a little disturbed right now.
I'm betting you meant
if ((my $r = &{$self->{onFile}}($path)) != SUCCESS) {
return $r;
}
Can I suggest that in future you produce a _minimal_ but _complete_
example that you have actually run and found to behave as you don't
expect. Post it together with a precices description of what it did and
what you expected.
This advice and much other useful advice can be found in the posting
guidelines.
- Next message: Tad McClellan: "Re: if statement oddity"
- Previous message: Jens Luedicke: "Re: if statement oddity"
- In reply to: Jens Luedicke: "if statement oddity"
- Next in thread: Gunnar Hjalmarsson: "Re: if statement oddity"
- Reply: Gunnar Hjalmarsson: "Re: if statement oddity"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]