Argh.. painful. Sorry, fellow monk, but that is a very fine example of how not to do it.
  1. No strict
  2. No warnings
  3. Use of & to call a function (unless you can explain to me what it does, and why it was necessary)
  4. Useless prototype in the function definition
  5. for(;;) to iterate over an array
  6. passing results via global variable

Funnily enough, you are already doing the work of "declaring" the variables (using =0; or =();), so you gained nothing by denying yourself the benefits of strict anyway. Why is the second regex in your code so much broader than the first? You end up comparing apples and oranges.. The print "\n.."; style is rather weird as well - not much to make a fuss about, but it just makes the code that bit uglier. And I have to say that, while a matter of taste, there's oodles of meaningless redundancy in your variable names.

Here's a clean version.
#!usr/bin/perl -w use strict; sub eat_array { my $array = shift; print "The array has " . @$array . " elements\n"; my ($minvalue) = ($array->[0] =~ /\|(\d+)$/); my ($minidx, $idx) = (0,0); foreach (@$array) { my ($currvalue) = (/\|(\d+)$/); if ($minvalue > $currvalue) { $minidx = $idx; $minvalue = $currvalue; } ++$idx; } my $minimum = splice @$array, $minidx, 1; print "Minimum is: $minimum\n"; return ($minimum, @$array ? eat_array($array) : ()); } my @testcase = ( 'a|a|1', 'a|a|9', 'a|a|0', 'a|a|12', 'a|a|3', 'a|a|4', 'a|a|3', 'a|a|6', 'a|a|9', 'a|a|1', 'a|a|5', 'a|a|7', 'a|a|15', 'a|a|0', 'a|a|8', 'a|a|4', ); print "\n"; my @results = eat_array(\@testcase); print @results . " elements.\n@results\n";
All the excercise is for naught though - there already is a built-in sort function. Not only does the old adage about reinventing a wheel apply, but in this of all cases, the existing one is a very good wheel and you need really, really unsual circumstances to justify a reinvention much less one that involves recursion.

Makeshifts last the longest.


In reply to Re^2: Sorting CSV array by Aristotle
in thread [untitled node, ID 178427] by Samn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.