>>>>> "KW" == Kenneth Wolcott <kennethwolc...@gmail.com> writes:

  KW>   The current output is a set of zero or more space separated
  KW> strings where each substring is a string of of three
  KW> dash-separated substrings.

you should always show sample input data and expected output (sorted
data). just describing it even when simple can be different than the
actual data.

  KW> I want to sort these space separated strings based on the middle of the
  KW> dash-separated substring.

  KW> The regex for the space-separated sub string is not exactly, but close to
  KW> the following regex.

  KW> [a-z0-9][a-z0-9]+-[A-Z][A-Z][A-Z]0z0r[1-9a-z][1-9]+-[c-z][a-z][1-9]

blech. if you really have dash seperators, use split. whenever you think
separartor think split.

  KW> Here is what I tried with awk, tr and sort:

and why would that matter in a perl question? keep on subject, how to
sort your data in perl

  KW> So should I do the same thing in Perl (ie: accumulate in an array
  KW> with push, then split, then sort?, then print)?

basically that is correct. there are various ways to handle that
too. one perl classic way is the schwartzian transform. a faster variant
is the GRT. you can learn how to code them from the Sort::Maker module
which can generate sort code in 4 styles. all you need to do is describe
how to get the key from the record. split makes that easy:

        (split /-/, $record)[1] 

that gets the middle field from a record.

  KW> I need to keep the Perl is simple and as maintainable as possible.

use that to start and either use the module and see what it generates or
google for those techniques and see what you can do. this is not
considered a complex sort at all. code up what you can and show it and
ask here for more help if you need.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to