- Original Message -
From: Matt Noel <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 16, 2001 7:05 PM
Subject: Sorting a Two Dimensional Array
(...)> I have a simple two-dimensional array, call it @Weights. I think of
the
> first index as being the
--- Jeff Pinyan <[EMAIL PROTECTED]> wrote:
> On May 16, Paul said:
>
> >"or" also short circuits, and some consider it more readable, but it
> >(and the "and" operator) always return(s) a boolean value, while ||
> >(and &&) return the value of the first true expression.
> >
> > $a or $b # retur
For a variable number of second-dimension elements, try:
my @sorted = sort { my($ndx,$ret) = (0,0);
while(defined($a->[$ndx]) and defined($b->[$ndx])) {
last if $ret = ($a->[$ndx] <=> $b->[$ndx++]);
}
$ret;
} @Weights;
This keeps comparing elements fro
On May 16, Paul said:
>"or" also short circuits, and some consider it more readable, but it
>(and the "and" operator) always return(s) a boolean value, while ||
>(and &&) return the value of the first true expression.
>
> $a or $b # returns 1 if either has a non-false value, else ''
> $a || $b
--- Paul Johnson <[EMAIL PROTECTED]> wrote:
> On Wed, May 16, 2001 at 10:05:14AM -0700, Matt Noel wrote:
> > I have a simple two-dimensional array, call it @Weights. I think
> > of the first index as being the Row index and the second being the
> > Column index. Normally I'd access an entry thu
On Wed, May 16, 2001 at 10:05:14AM -0700, Matt Noel wrote:
> I have a simple two-dimensional array, call it @Weights. I think of the
> first index as being the Row index and the second being the Column
> index. Normally I'd access an entry thus:
>
> $ItemWeight = $Weights[$row][$col];
>
> I
I've been through the Perl Cookbook and Programming Perl trying to
figure this one out, now I'm ready for some help. I've been working
with Perl for years but I can't make heads nor tails out of the
explanations in either of these books on the subject of sorting. Sigh.
I have a simple two-dimen