Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I agree with merlyn that it's better to try to grok the ST before the GRT, which, after all, is a special case of the ST. I'm not sure that the ST is always clearer, however.

Interesting that the example of sorting IP addresses is used here, because that was the original scenario in which the GRT was first explored (by Michal Rutka, Uri Guttman, Larry Rosler and myself). We could probably say that it is a canonical example: The data itself is very simple, the string representation cannot be (usefully) used for sorting, and the transformation to and from a meaningfully sortable representation is trivial.

@ips = # note: this converts any "unusual" reps to dotted-quad map { inet_ntoa $_ } sort map { inet_aton $_ } @ips;
Or, to sort lines which have IPs embedded:
@ips = map { substr $_, 4 } sort map { /(\d[.\d]+\d)/; inet_aton($1) . $_ } @ips;

As you can see, this is no less clear than the equivalent ST. The maps are arguably simpler; and of course the sort is more trivial, since that's always the case.

But sorting IPs is something of a special case. In general, one would probably have to resort to either pack or sprintf to generate the sortable string.


In reply to Re: Understanding transformation sorts (ST, GRT), the details by jdporter
in thread Understanding transformation sorts (ST, GRT), the details by 5mi11er

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (10)
    As of 2014-11-26 08:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (164 votes), past polls