Re: Conditional Operator

2008-12-05 Thread James Moser
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Dec 5, 2008, at 11:42 AM, Jenda Krynicky wrote: In Perl 5.10 there is a new operator // that tests the defined()ness so there you could write $title = $title1 // $title2 // $old_title; and it would mean exactly what you said you need. It will s

Re: Conditional Operator

2008-12-05 Thread Jenda Krynicky
From: Dermot <[EMAIL PROTECTED]> > 2008/12/5 Raymond Wan <[EMAIL PROTECTED]>: > > Maybe I have missed something, but it sounds like you want something like > > [NB: This is not Perl code, but sort of pseudocode]: > > > > if (defined (title1)) { > > $title = title1; > > } > > elsif (defined (title

Re: Conditional Operator

2008-12-05 Thread James Moser
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Dec 5, 2008, at 10:34 AM, Dermot wrote: I was looking to test title1 and return that if it was defined else, test title2 and return that if defined, failing that, return oldtitle. The ? : operator won't do that. It tests title1 and if true return

Re: Conditional Operator

2008-12-05 Thread Dermot
2008/12/5 Raymond Wan <[EMAIL PROTECTED]>: > > Hi Dermot, > > > Dermot wrote: >> Sorry. Someone on the list mentioned to me before, a reference is >> always true, so the test won't work. >> > > Maybe I have missed something, but it sounds like you want something like > [NB: This is not Perl code,

Re: Conditional Operator

2008-12-05 Thread Raymond Wan
either title1 or title2, but would prefer title1 -- hence the order of the pseudocode above.) See http://perldoc.perl.org/perlop.html#Conditional-Operator to confirm whether or not it is what you want. Ray -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Conditional Operator

2008-12-05 Thread Dermot
2008/12/5 Dermot <[EMAIL PROTECTED]>: > Hi, > > I have some data from a dbi that looks like this: > > +---+---+++ > | title1 | title2 | oldtitle > --++ > | NULL | NULL | The cat jumped over

Conditional Operator

2008-12-05 Thread Dermot
Hi, I have some data from a dbi that looks like this: +---+---+++ | title1 | title2 | oldtitle --++ | NULL | NULL | The cat jumped over the mat I used this statement to try and grab 1st,

Re: Conditional operator

2007-03-07 Thread John W. Krahn
Rob Dixon wrote: > Dr.Ruud wrote: >> >> Karyn Williams schreef: >> >>> $initial ? >>> $gecos = "$first $initial $last, $sid, SIR Fall 2007": >>> $gecos = "$first $last, $sid, SIR Fall 2007"; >> >> Variant-1: >> >> $gecos = $first; >> $gecos .= " $initial

Re: Conditional operator

2007-03-07 Thread Rob Dixon
Dr.Ruud wrote: > Karyn Williams schreef: $initial ? $gecos = "$first $initial $last, $sid, SIR Fall 2007": $gecos = "$first $last, $sid, SIR Fall 2007"; Variant-1: $gecos = $first; $gecos .= " $initial" if $initial; $gecos .= " $last, $sid, SIR

Re: Conditional operator

2007-03-07 Thread Dr.Ruud
Karyn Williams schreef: > $initial ? > $gecos = "$first $initial $last, $sid, SIR Fall 2007": > $gecos = "$first $last, $sid, SIR Fall 2007"; Variant-1: $gecos = $first; $gecos .= " $initial" if $initial; $gecos .= " $last, $sid, SIR Fall 2007"; V

Re: Conditional operator

2007-03-07 Thread Karyn Williams
At 10:04 AM 3/7/07 -0800, Tom Phoenix wrote: >On 3/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote: > >> if ($initial =~ "") { > >You probably don't want the binding operator =~ in there, but the >string equality test eq, right? Check the perlop manpage. Good luck >with it! Using the eq op

Re: Conditional operator

2007-03-07 Thread Karyn Williams
At 09:58 AM 3/7/07 -0800, Karyn Williams wrote: >At 09:35 AM 3/7/07 -0800, Tom Phoenix wrote: >>On 3/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote: >> >>> I have a script where I am trying to use the conditional operator. >>> Apparently I a

Re: Conditional operator

2007-03-07 Thread Tom Phoenix
On 3/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote: if ($initial =~ "") { You probably don't want the binding operator =~ in there, but the string equality test eq, right? Check the perlop manpage. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail:

Re: Conditional operator

2007-03-07 Thread Karyn Williams
At 09:35 AM 3/7/07 -0800, Tom Phoenix wrote: >On 3/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote: > >> I have a script where I am trying to use the conditional operator. >> Apparently I am confused as it always evaluates false. > >> $initial ? >>

Re: Conditional operator

2007-03-07 Thread Tom Phoenix
On 3/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote: I have a script where I am trying to use the conditional operator. Apparently I am confused as it always evaluates false. $initial ? $gecos = "$first $initial $last, $sid, SIR Fall 2007":

Conditional operator

2007-03-07 Thread Karyn Williams
I have a script where I am trying to use the conditional operator. Apparently I am confused as it always evaluates false. These are the relevant lines from the script. The scalar $initial will either be "" or "A". Can someone help me to understand what I clearly don't.

Re: Conditional Operator && STDIN

2002-06-03 Thread bob ackerman
On Monday, June 3, 2002, at 10:45 AM, bob ackerman wrote: > > On Monday, June 3, 2002, at 10:37 AM, Jeff 'japhy' Pinyan wrote: > >> On Jun 3, bob ackerman said: >> @ARGV = "< $filename" if $opt_f; >>> >>> why '<' ? isn't '$filename' enough for get '<>' to open and read from >>> that >>

RE: Conditional Operator && STDIN

2002-06-03 Thread Nikola Janceski
; From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] > Sent: Monday, June 03, 2002 1:38 PM > To: bob ackerman > Cc: [EMAIL PROTECTED] > Subject: Re: Conditional Operator && STDIN > > > On Jun 3, bob ackerman said: > > >> @ARGV = "< $filen

Re: Conditional Operator && STDIN

2002-06-03 Thread bob ackerman
On Monday, June 3, 2002, at 10:37 AM, Jeff 'japhy' Pinyan wrote: > On Jun 3, bob ackerman said: > >>> @ARGV = "< $filename" if $opt_f; >> >> why '<' ? isn't '$filename' enough for get '<>' to open and read from >> that >> file? > > I feel safer when I explicitly state the mode. Unless you w

Re: Conditional Operator && STDIN

2002-06-03 Thread Jeff 'japhy' Pinyan
On Jun 3, bob ackerman said: >> @ARGV = "< $filename" if $opt_f; > >why '<' ? isn't '$filename' enough for get '<>' to open and read from that >file? I feel safer when I explicitly state the mode. Unless you want the user to put 'foo |' as the filename (that is, the output of a pipe), then y

Re: Conditional Operator && STDIN

2002-06-03 Thread bob ackerman
On Monday, June 3, 2002, at 09:27 AM, Jeff 'japhy' Pinyan wrote: > On Jun 3, Balint, Jess said: > >> Hello all. I am working on my script, and I would like to be able to use >> STDIN as a filehandle input unless a filename is specified. I have used >> the >> getopt for the filename, let's say

Re: Conditional Operator && STDIN

2002-06-03 Thread Jeff 'japhy' Pinyan
On Jun 3, Balint, Jess said: >Hello all. I am working on my script, and I would like to be able to use >STDIN as a filehandle input unless a filename is specified. I have used the >getopt for the filename, let's say $opt_f. I would use the magic of @ARGV and <>, and do this: @ARGV = "< $filen

Conditional Operator && STDIN

2002-06-03 Thread Balint, Jess
Hello all. I am working on my script, and I would like to be able to use STDIN as a filehandle input unless a filename is specified. I have used the getopt for the filename, let's say $opt_f. I thought I would do something like this: ( $opt_f ) ? open( INFILE, "$opt_f" ) or die( "Can't open...)

Re: Using the conditional operator

2002-02-07 Thread Brett W. McCoy
On Thu, 7 Feb 2002, Balint, Jess wrote: > Hello all. I have the following construct: > > $freqidx{$key}[$_] += $fields[$vars[$_-1]] for( 0..$#vars ); > > It is inside some type of loop. What I need to do is use the conditional > operator if possible to do something

Using the conditional operator

2002-02-07 Thread Balint, Jess
Hello all. I have the following construct: $freqidx{$key}[$_] += $fields[$vars[$_-1]] for( 0..$#vars ); It is inside some type of loop. What I need to do is use the conditional operator if possible to do something like this: if( $fields[$vars[$_-1]] ne "" ) { $fr