Re: Consolidate if/else
"Surround them"... and ... better use +ve logic : $opt_Z ? ( $mkt = $opt_Z) : ( die "Must supply Market\n" ); or $opt_Z ? { $mkt = $opt_Z} : { die "Must supply Market\n" }; Rgds, Connie - Original Message - From: "Kevin Old" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, July 17, 2002 4:54 AM Subject: Consolidate if/else > > Hello all, > > I'm trying to get this line to work > > (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; > > and I keep getting compiler errors. > > > Basically I'm trying to consolidate: > > if (!$opt_Z) { > die "Must supply Market\n"; > } else { > $mkt = $opt_Z; > } > > > Any ideas? > > Thanks, > Kevin > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
Better use defined on $opt_Z , cause it will die even if $opt_Z has 0 , '0' or space !! > > Hello all, > > I'm trying to get this line to work > > (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; >You need parens because assignment is lower precedence than ternary: > > (!$opt_Z) ? die "Must supply Market\n" : ($mkt = $opt_Z); >But the following is equivalent, but more readable: > $mkt = $opt_Z or die "Must supply Market\n"; >(n.b. "or" is needed instead of "||", since it has super low precedence) > > > and I keep getting compiler errors. > > > Basically I'm trying to consolidate: > > if (!$opt_Z) { > die "Must supply Market\n"; > } else { > $mkt = $opt_Z; > } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
On Jul 16, Bob Showalter said: > $mkt = $opt_Z or die "Must supply Market\n"; > >(n.b. "or" is needed instead of "||", since it has super low precedence) Well, it's not important here, since die() will end the process. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Consolidate if/else
> (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; $mkt = $opt_Z || die "Must supply Market\n"; jjv -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Consolidate if/else
That's also kind of obfuscated...you might try die "Must supply Market\n" unless $mkt = $opt_Z; - Original Message - From: "Kevin Old" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 16, 2002 4:54 PM Subject: Consolidate if/else > > Hello all, > > I'm trying to get this line to work > > (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; > > and I keep getting compiler errors. > > > Basically I'm trying to consolidate: > > if (!$opt_Z) { > die "Must supply Market\n"; > } else { > $mkt = $opt_Z; > } > > > Any ideas? > > Thanks, > Kevin > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
> -Original Message- > From: Kevin Old [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 16, 2002 4:54 PM > To: [EMAIL PROTECTED] > Subject: Consolidate if/else > > > > Hello all, > > I'm trying to get this line to work > > (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; You need parens because assignment is lower precedence than ternary: (!$opt_Z) ? die "Must supply Market\n" : ($mkt = $opt_Z); But the following is equivalent, but more readable: $mkt = $opt_Z or die "Must supply Market\n"; (n.b. "or" is needed instead of "||", since it has super low precedence) > > and I keep getting compiler errors. > > > Basically I'm trying to consolidate: > > if (!$opt_Z) { > die "Must supply Market\n"; > } else { > $mkt = $opt_Z; > } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Consolidate if/else
On Jul 16, Kevin Old said: >I'm trying to get this line to work > >(!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; > >and I keep getting compiler errors. You should reproduce the error so we don't have to, but I know the error already. Something like "cannot modify die in assignment"? The ?: operator binds more tightly than the = operator, so your code reads like (!$opt_Z ? die "..." : $mkt) = $opt_Z; This makes Perl think you're going to assign to either $mkt or the return value of die(), and the latter is impossible. Either parenthesize the assignment: !$opt_Z ? die "..." : ($mkt = $opt_Z); or swap the two: $opt_Z ? $mkt = $opt_Z : die "..."; Or better yet, use the following idiom: $mkt = $opt_Z or die "..."; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
precedence.. ?: has lower precedence than {} change it to: (!$opt_Z) ? die("Must supply Market\n") : $mkt = $opt_Z; > -Original Message- > From: Kevin Old [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 16, 2002 4:54 PM > To: [EMAIL PROTECTED] > Subject: Consolidate if/else > > > > Hello all, > > I'm trying to get this line to work > > (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; > > and I keep getting compiler errors. > > > Basically I'm trying to consolidate: > > if (!$opt_Z) { > die "Must supply Market\n"; > } else { > $mkt = $opt_Z; > } > > > Any ideas? > > Thanks, > Kevin > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
>Hello all, >I'm trying to get this line to work >(!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; >and I keep getting compiler errors. $mkt = (defined ($opt_Z)) ? $opt_Z : die("Must supply Market\n"); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Consolidate if/else
Turn on warnings and use strict, and let us know what your errors are. -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 16, 2002 1:54 PM To: [EMAIL PROTECTED] Subject: Consolidate if/else Hello all, I'm trying to get this line to work (!$opt_Z) ? die "Must supply Market\n" : $mkt = $opt_Z; and I keep getting compiler errors. Basically I'm trying to consolidate: if (!$opt_Z) { die "Must supply Market\n"; } else { $mkt = $opt_Z; } Any ideas? Thanks, Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]