in reply to compare arrays numbers

Why? As already shown there are many ways of hiding a loop, but unless we know why you want to do this strange thing it's not clear that any of the subterfuges mentioned above will be of any use to you.

If you are concerned with efficiency, don't be (this is Perl and it ain't built for that) or use XS (a module written in C) to perform the time critical part. An existing module such as PDL may be able to do the heavy lifting for you.


True laziness is hard work

Replies are listed 'Best First'.
Re^2: compare arrays numbers
by etj (Priest) on May 29, 2022 at 22:27 UTC
    I'd say (possibly being biased) that the avoidance of for-loops using https://en.wikipedia.org/wiki/Array_programming constructs both saves programmer time, reader/maintenance time, and (thanks to not having to enter/leave Perl land lots in a repetitive way) execution time. PDL provides such array-programming constructs, e.g. $out_pdl = $in1_pdl - $in2_pdl which works however large the two input ndarrays are.