SPUG: trinary ? operator
Meryll Larkin
humbaba9 at yahoo.com
Fri Jan 25 20:06:40 CST 2002
1/25/02
Thanks Daryn,
I was able to get that to work in with both integers
and strings. You were right, I was trying to do this:
if ($boolean == "y") {
$boolean = 1;
}
else {
$boolean = 0;
}
Meryll
--- Daryn Nakhuda <daryn at marinated.org> wrote:
>
> what are you trying to do exactly?
>
> what you typed is equivalent to:
>
> if ($ok) {
> $a = $b;
> }
> else {
> $a = $c;
> }
>
> if you meant to do
>
> if ($a == $ok) {
> $something = $b;
> }
> else {
> $something = $c;
> }
>
> that'd be
>
> $something = ($a == $ok) ? $b : $c;
>
>
>
>
> On Fri, 25 Jan 2002, Meryll Larkin wrote:
>
> > 1/25/02
> >
> > Hi Folks,
> >
> > I'm using Active Perl5.005_03 on Windows98 and
> 5.6.1
> > on Windows2000 professional edition and I can't
> get
> > the trinary ? operator to work. Does anyone have
> any
> > experience with this in Windows? Does my syntax
> need
> > correcting?
> >
> > On pg 92 of Programming Perl (2nd Edition) an
> example
> > of the trinary operator is given:
> >
> > $a = $ok ? $b : $c;
> >
> > I find if I use this syntax, I get an assignment
> to $b
> > (the "true" choice) because $a = $ok has a single
> =
> > instead of ==.
> >
> > If I try to use == I don't get an error, the
> entire
> > line seems to be ignored.
> >
> > If I use strings and use "eq" the line is also
> > ignored.
> >
> > Turning on -w gets me this error:
> > Useless use of private variable in void context.
> > Useless use of private variable in void context.
> > (yes, twice, I assume it refers to $b and $c)
> >
> > help?
> >
> > Meryll
> >
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Great stuff seeking new owners in Yahoo! Auctions!
>
> > http://auctions.yahoo.com
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - - - - - -
> > POST TO: spug-list at pm.org PROBLEMS:
> owner-spug-list at pm.org
> > Subscriptions; Email to majordomo at pm.org:
> ACTION LIST EMAIL
> > Replace ACTION by subscribe or unsubscribe,
> EMAIL by your Email-address
> > For daily traffic, use spug-list for LIST ; for
> weekly, spug-list-digest
> > Seattle Perl Users Group (SPUG) Home Page:
> http://zipcon.net/spug/
> >
> >
>
> --
>
>
__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
More information about the spug-list
mailing list