k_manimuthu has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I need to assign $string = 'some values' based on the length of the array. If length of the array equals to '-1' I want to assign $string = 'True', otherwise I expect $string = 'False'.
I got $string = 'False' even though the array values is equals to '-1'. But i am add a line to test the array value, I got the output as 'True'. I am confused, why the code's gives the mismatch output.
Below I placed the code. Could someone please explain on this.
Thanks
Mani Muthu
use strict; use warnings; my @arr; my $string = 'Initial'; ($#arr == -1 ) ? print "True" : print "False"; ($#arr == -1 ) ? $string = 'True' : $string = 'False'; print "\n\$string = $string"; print "\n\$#arr = $#arr"; =Output True $string = False $#arr = -1 =cut
Note : I am using perl 5.8.9 in Windows
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected Output
by cdarke (Prior) on Jul 28, 2010 at 08:22 UTC | |
|
Re: Unexpected Output
by moritz (Cardinal) on Jul 28, 2010 at 08:15 UTC | |
|
Re: Unexpected Output
by Corion (Patriarch) on Jul 28, 2010 at 08:17 UTC | |
|
Re: Unexpected Output
by nvivek (Vicar) on Jul 28, 2010 at 11:41 UTC | |
|
Re: Unexpected Output
by Khen1950fx (Canon) on Jul 28, 2010 at 08:33 UTC | |
|
Re: Unexpected Output
by Your Mother (Archbishop) on Jul 28, 2010 at 16:21 UTC | |
by k_manimuthu (Monk) on Jul 29, 2010 at 07:26 UTC |