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:
>
> if(@$a > @$b) {
> $n = (@$a > @$a); # $n = 0 because @$a is not greater than itself
> } else {
> $n = (@$a > @$b); # $n could be 1 or 0 depending on the values of @$a and @$b
> }
Wrong.
> I believe what you meant to do is:
>
> my $n = (@$a > @$b) ? @$a : @$b;
The parentheses are not required.
$ perl -le'
$a = [ 2,3,4,5 ]; $b = [ @$a, 6,7 ];
print @$a . " " . @$b;
$n = @$a > @$b ? @$a : @$b; print $n;
( $a, $b ) = ( $b, $a );
print @$a . " " . @$b;
$n = @$a > @$b ? @$a : @$b; print $n;
'
4 6
6
6 4
6
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>