RE: REGEXP removing - il- - -b-f and - il- - - - f
- From: errinlarsen@xxxxxxxxxxx (Errin M HMMA/IT Larsen)
- Date: Fri, 29 Apr 2005 09:24:21 -0500
> -----Original Message-----
> From: John Doe [mailto:security.department@xxxxxxxx]
> Sent: Friday, April 29, 2005 8:50 AM
> To: beginners@xxxxxxxx
> Subject: Re: REGEXP removing - il- - -b-f and - il- - - - f
>
>
> Am Freitag, 29. April 2005 14.43 schrieb DBSMITH@xxxxxxxxxxxxxx:
> > So which is safer more ideal to use : || , or
> >
> >
> > Derek B. Smith
> > OhioHealth IT
> > UNIX / TSM / EDM Teams
> [...]
>
> The only difference between "||" and "or" is the precedence, and the
> precedence of "=" lies between them.
>
> To my understanding, in the "assign or die" special case,
>
> my $a=do_something_which_can_fail() or handle_exception();
I'm sure I'll be corrected if I am wrong, but I believe that Perl sees
the above line of code like this:
( my $a = do_something_which_can_fail() ) or ( handle_exception() );
Because of the low precedence of the "or" operator. Therefore, Perl
will try to assign the return value of "do_something_which_can_fail()"
subroutine to $a, and if it can't, THEN perl will execute the
"handle_exception()" subroutine. This is probably what the coder
wanted.
>
> is more logic than
>
> my $a=do_something_which_can_fail() || handle_exception();
Perl sees THIS line of code like this:
my $a = ( ( do_something_which_can_fail() ) || ( handle_exception() )
);
Because of the high precedence of the "||" operator. Therefore, perl
will run the "do_something which can fail()" subroutine, and if it
succeeds, assign the value returned to $a. OTHERWISE, if it fails, the
return value from "handle_exception()" subroutine will be assigned to
$a. This is probably NOT what you want to happen.
>
> because something should be assigned to $a, and if that
> fails, the app should
> e.g. die. This way, the exception handling is not part of the
> assignement.
>
> On the other side, I would use
>
> my $a=do_something_which_can_fail() || provide_some_default();
>
> because the exception handling consists of providing a value.
>
> Just my personal way to look at it :-)
>
> joe
>
--Errin Larsen
.
- Prev by Date: RE: REGEXP removing - il- - -b-f and - il- - - - f
- Next by Date: Re: REGEXP removing - il- - -b-f and - il- - - - f
- Previous by thread: changing permissions in order to write a file in Mod_perl
- Next by thread: problems with SerialPorts, Modems, IOCTL
- Index(es):
Relevant Pages
|