f77coder: Further to NetWallah's post, you have to realize that Perl strings are not arrays (e.g., not in the sense that C strings are char arrays). However, they do both have 'length' (number of characters vs. number of elements) and so are comparable. But when you mix strings and array references promiscuously, you must be sure each element is correctly recognized so its 'length' can be correctly derived. (This code assumes only strings and array references are mixed together, and also has a shuffle example.)

c:\@Work\Perl>perl -wMstrict -le "use List::Util qw(shuffle); use Data::Dump; ;; my @ra_1 = qw(a b c d); my @ra_2 = (1 .. 9); my @ra_3 = qw(p z e t i u); my @ra_4 = qw(foo bar baz); ;; my @AoA = (\@ra_1, 'foozle', \@ra_2, 'red', \@ra_3, \@ra_4); dd \@AoA; ;; my @sorted = sort { (ref $a ? @$a : length $a) <=> (ref $b ? @$b : length $b) } @AoA ; dd \@sorted; ;; my @shuffled = shuffle @sorted; dd \@shuffled; " [ ["a" .. "d"], "foozle", [1 .. 9], "red", ["p", "z", "e", "t", "i", "u"], ["foo", "bar", "baz"], ] [ "red", ["foo", "bar", "baz"], ["a" .. "d"], "foozle", ["p", "z", "e", "t", "i", "u"], [1 .. 9], ] [ [1 .. 9], ["a" .. "d"], "foozle", ["foo", "bar", "baz"], "red", ["p", "z", "e", "t", "i", "u"], ]


In reply to Re^3: multiple array processing by AnomalousMonk
in thread multiple array processing by f77coder

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.