Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • And yeah, you can make a case for returning an item count instead of just undef.
    • See my perlmonks posting on scalar context [perlmonks.org]. "Count" is actually in the minority for things being returned in a scalar context.

      I think a much more interesting thing would be a floating point value between 0 and 1 of how many adjacent pairs of items already meet the sort criteria, so "1..5" would be 1, but "reverse 1..5" would be 0.

      --
      • Randal L. Schwartz
      • Stonehenge
      • That sortedness factor you propose sounds really useless. 0 + sort qw( 1 3 5 7 9 0 2 4 6 8 10 ) would return 0.9. But what am I supposed to conclude from that? The list is certainly not 90% sorted, nor can I think of any other way in which this metric might be useful.

        OTOH, returning the item count would allow parity for

        sub foo { sort @_ }

        with

        sub bar { map $_, @_ }

        and

        sub baz { grep 1, @_ }

        in scalar context.

        And item count in scalar context is actually the majority among functions that take a l [perlmonks.org]