RE: REGEXP removing - il- - -b-f and - il- - - - f



> -----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
.



Relevant Pages

  • Linux Magazin: Perl gewinnt haushoch gegen die anderen Skriptsprachen
    ... [@Randal, in case your German's not so good: I was dismayed how they turned this contest around, to make it seem at first sight like you and Perl had completely failed. ... Klar ist es blöd, daß alle nach dem Motto programmieren, CPU und Speicher seien eh da. ... Da ich bei makepp viel Erfahrung mit Perl Optimierung gesammelt habe, bin ich da gerne ran gegangen. ... Randal hat achtlos die drei Infos pro Fußnote in einen Hash gespeichert. ...
    (comp.lang.perl.misc)
  • =?iso-8859-1?q?Re:_Einer_Subroutine_2_Hashes_=FCbergeben?=
    ... Aber wenn ich eine Subroutine schreibe, ... glücklicherweise jeder post FORTRAN Programmierer "call by ... "You may still declare a sub just as you did in Perl 5, ...
    (de.comp.lang.perl.misc)
  • Re: Perl Multithreading and use of Perl Modules
    ... >> I'm trying to create a multithreaded program in Perl 5.8 on Linux. ... The tracker() subroutine needs to be able to check the shared variables ...
    (comp.lang.perl.misc)
  • Re: Einer Subroutine 2 Hashes =?ISO-8859-1?Q?=FCbergeben?=
    ... > die Zuweisung im Funktionsaufruf völlig" dieselbe Semantik? ... > einen Ausdruck) an eine Subroutine übergibst, ... Die "Referenz" kann ja auch weitergereicht werden. ... Die von Perl gebotene Möglichkeit, ...
    (de.comp.lang.perl.misc)
  • RE: Perl / Apache on RH9.0 not working.
    ... script perl usually tells you there are returns but this time it didn't. ... > PerlInitHandler - Subroutine name ...
    (RedHat)