On Fri, Jan 10, 2003 at 10:23:43AM -0600, Jensen Kenneth B SrA AFPC/DPDMPQ wrote:
> In the line
> my $max = (sort {$b<=>$a} ($x, $y, $z))[0];
>
> What is the "[0]" doing?
This part:
(sort {$b<=>$a} ($x, $y, $z))
creates a list. The "[0]" returns the first element in that list.
> Also another question. While messing around with the compact version of if
> statements I tried these.
>
> $one = 1;
> ($one == 1) ? (print "\$one equals", print "$one") : (print "\$one does not
> ", print "equal 1");
>
> Returns
> 1
> $one equals 1
>
> At first I thought the first "1" on a line by itself was a return flag or
> something,
That's exactly what it is. To Perl, this:
print "\$one equals", print "$one"
means this (letters on the left are just for reference):
A) print a list consisting of:
B) - the string "\$one equals" and
C) - the value returned from evaluating the expression
'print "$one"'
Before it can do (A), it needs to figure out the value of (C). So, it
evaluates (C). That outputs the value of "$one" (which happens to be
1) to the screen, and returns 1 (because print always returns 1 if
successful). (A) now has its argumnt list figured out, so it prints
them, which outputs the string "$one equals 1".
Had you done this instead:
$one = 7;
($one == 7) ?
(print "\$one equals ", print "$one")
: (print "\$one does not ", print "equal 1")
;
You would have seen this:
7
$one equals 7
However, why there is a newline after the initial 1, I'm not sure...is
there anything in your code that you haven't shown us? For example,
did you set the $\ variable?
Given the above, you should be able to step through the other examples
you gave and figure out what's going on. Just work from the inside
out.
--Dks
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]