Some resources re sorting:
  1. http://perldoc.perl.org/perlfaq4.html#How-do-I-sort-an-array-by-%28anything%29%3f
  2. Replies in MsExcel like Multi Column Sorting
  3. Super Search
    ...and
  4. "Learning Perl" (AKA "The Llama book") Schwartz, foy & Phoenix, O'Reilly, esp Ch 15

The preferred data structure will depend on how you want to use the data later -- your notion of a hash with epoch_times as the keys will be straightforward (the time will be converted to a string, but that's not an issue); putting the data into a database (SQLite, for one) will give the power to manipulate and retrieve it in many ways.

And you certainly could put it in an array if the format you show is absolutely guaranteed to be invariant:

  1. split offers the option of splitting once, after the first space:
    @array = split /PATTERN/,EXPR,LIMIT
    where epoch_time will be the first, third, fifth (and so on) elements of the array to which you've split
  2. or making three fields:
    split /PATTERN/,EXPR

TIMTOWTDI: could be much more elegant (MUCH more!) but this may be easy to follow:

#!/usr/bin/perl use strict; use warnings; #825421 use Data::Dumper; my (@array, @tmp, $time, $fields); my @lines = <DATA>; for my $line(@lines) { chomp $line; ($time, $fields) = split / /, $line, 2; push @array, $time; push @array, $fields; } my @arr2; for my $line(@lines) { chomp $line; my @tmp2 = split / /, $line; for my $element2(@tmp2) { push @arr2, ($element2 . "\t"); } } print "\n first array \n"; for $_(@array) { print "$_ \n"; } print "\n"; print "\n second array\n"; for $_(@arr2) {print "$_ \n "; } print "\n"; __DATA__ 12345 f1 f2 23456 F3 F4 98765 f-five f-six<c> <p>Output:</p> <c> first array 12345 f1 f2 23456 F3 F4 98765 f-five f-six second array 12345 f1 f2 23456 F3 F4 98765 f-five f-six

Updated code and output after initially (and dumb-ly!) pasting both in a form that didn't even come close to OP's spec.

Code for sorting left as an exercise for elwoodblues. :-)


In reply to Re: best way to sort by ww
in thread best way to sort by elwoodblues

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.