Phoenix.pm: Perl stuuf

Peter J Jones p at dancris.com
Thu Mar 4 23:44:15 CST 1999


Shay Harding wrote:

> >Shay Harding wrote:
> >
> >> On Tue, 02 Mar 1999, you wrote:
> >> >Hey, look! An actual Perl-related email!
> >> >
> >> >So, I have this little update pl fed by an HTML form. One of the things it
> >> >does is to store a copy of the updated content seperate so that it can be
> >> >edited later. So, here is where it gets wierd...
> >> >
> >> >$text = $FORM{'text'};
> >> >$action = $FORM{'action'};
> >> >$action = "nada" unless $action;
> >>      ### $action = "nada" if !$action; ### :)
> >
> >or even less typing...
> >$action |= "nada";
>

You got me... should be $action ||= "nada";

>
> You want to overload the bitwise OR operator? What if $action already has a
> value? Then the current value of $action and "nada" get ORed together bit by
> bit. Will probably not work as expected.
>
> Consider the following code:
>
> # Assign $FORM{'action'} to $action
>
> $action = $FORM{'action'};
>
> # Bitwise OR the current value of ($action & "nada") and assign it to $action
> $action |= "nada";
>
> #print the result
>
> print"$action\n";
>
> Now if $FORM{'action'} has the value of "norm" then when you print $action you
> will get "novm" and not "nada" or "norm".
>
> This may still work in some instances like if $FORM{'action'} had the value of
> "none" the result would be 'none' since (none |= nada) = none
>
> Sounds like you've used this somewhere? Can you post the code? Maybe I'm
> missing something here?
>
> --
>
> Shay Harding
> sharding at ccbill.com




More information about the Phoenix-pm mailing list