Re: condition in a single line

2008-08-23 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > On Thu, 2008-08-21 at 21:55 -0700, Noah wrote: >> Is there a way to simplify the following to one line? >> my $value = $t1lsq{$interfaceName}; >> $value = 4 if $value > 4; > > Simple in a Rube Goldberg's kind of way ;) > ( $value ) = sort { $a <=> $b }

Re: condition in a single line

2008-08-22 Thread Robert Citek
An alternate version: my $value = ( $t1lsq{$interfaceName} >= 4) ? 4 : $t1lsq{$interfaceName}; and a test: $ perl -le ' $t1lsq{$interfaceName}=2 ; my $value = ( $t1lsq{$interfaceName} >= 4) ? 4 : $t1lsq{$interfaceName}; print $value ' 2 $ perl -le ' $t1lsq{$interfaceName}=5 ; my $value = ( $t1l

Re: condition in a single line

2008-08-22 Thread Peter Scott
On Fri, 22 Aug 2008 07:15:49 -0700, John W. Krahn wrote: > Peter Scott wrote: >> my $value = max( 4, $t1lsq{$interfaceName} ); > > s/max/min/ > > :-) Wow, they are different. Maybe that explains my overdraft... -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To

Re: condition in a single line

2008-08-22 Thread John W. Krahn
Peter Scott wrote: On Thu, 21 Aug 2008 21:55:46 -0700, Noah wrote: Is there a way to simplify the following to one line? my $value = $t1lsq{$interfaceName}; $value = 4 if $value > 4; If you happen to already have use List::Util qw(max); in your code

Re: condition in a single line

2008-08-22 Thread Peter Scott
On Thu, 21 Aug 2008 21:55:46 -0700, Noah wrote: > Is there a way to simplify the following to one line? > > my $value = $t1lsq{$interfaceName}; > $value = 4 if $value > 4; If you happen to already have use List::Util qw(max); in your code (or don't mind

Re: condition in a single line

2008-08-22 Thread Rob Dixon
Noah wrote: > > Is there a way to simplify the following to one line? > > > --- > > my $value = $t1lsq{$interfaceName}; > $value = 4 if $value > 4; I'm wondering why you want to do that? Depending on your reasons, perhaps this would do? my $value = $t1lsq{

Re: condition in a single line

2008-08-22 Thread Mr. Shawn H. Corey
On Thu, 2008-08-21 at 21:55 -0700, Noah wrote: > Hi there, > > Is there a way to simplify the following to one line? > > > --- > > my $value = $t1lsq{$interfaceName}; > $value = 4 if $value > 4; > > > > > Simple in a Rube Goldberg's kind of way ;) (

Re: condition in a single line

2008-08-22 Thread Dr.Ruud
Noah schreef: > Is there a way to simplify the following to one line? > >my $value = $t1lsq{$interfaceName}; >$value = 4 if $value > 4; Not really. You might not want to get $t1lsq{$interfaceName} twice, because of side effects for example, one being that it is just slower to do things tw

Re: condition in a single line

2008-08-21 Thread Raymond Wan
John W. Krahn wrote: If you consider this to be simpler: my $value = $t1lsq{ $interfaceName } > 4 ? 4 : $t1lsq{ $interfaceName }; Oh, yes, of course! Opps, ignore my suggested line of code... :-) Ray -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PR

Re: condition in a single line

2008-08-21 Thread John W. Krahn
Noah wrote: Hi there, Hello, Is there a way to simplify the following to one line? my $value = $t1lsq{$interfaceName}; $value = 4 if $value > 4; If you consider this to be simpler: my $value = $t1lsq{ $interfaceName } > 4 ? 4 : $t1lsq{ $interfaceName }; John -- Perl isn't a to

Re: condition in a single line

2008-08-21 Thread Raymond Wan
Hi Noah, The ?: operator would do the trick: http://www.perl.com/doc/manual/html/pod/perlop.html#Conditional_Operator I think what you need would be this, but I haven't tried it: (my $value > 4) ? ($value = 4) : ($value = $t1lsq{$interfaceName}); Ray Noah wrote: Hi there, Is there a