Andrew Gaffney wrote:
> Perl wrote:
> > I am trying to understand how this works. For example:
> >
> > my $n = @$a > @$b ? @$a : @$b;
> >
> >
> > I understand this is a conditional statement I am just not sure what is
> > being compared with ? and :.
>
> I believe that the above just assigns a true or false (1 or 0) to $n. The statement
> is the
> same as:
Not really. More like
>
>
> if(@$a > @$b) {
> $n = @$a;
> } else {
> $n =$b;
> }
>
> I believe what you meant to do is:
>
> my $n = (@$a > @$b) ? @$a : @$b;
Although it is not necessary the meaning might be better expressed:
my $n = (@$a > @$b ? @$a : @$b)
The hierarchy of operator precedence obviates the need for parenteses here, though.
Refer to
perldoc perlop
for the full table, but the relative hierarchy among the operators shown above is:
> comparison first
? : conditional next
= assignment last
Joseph
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>