Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: To use a module...or not.

by diotalevi (Canon)
on Jul 26, 2004 at 02:55 UTC ( [id://377343]=note: print w/replies, xml ) Need Help??


in reply to Re^2: To use a module...or not.
in thread To use a module...or not.

Step backwards in time and rediscover fixed length records.

Replies are listed 'Best First'.
Re^4: To use a module...or not.
by BrowserUk (Patriarch) on Jul 27, 2004 at 13:29 UTC

    I've taken a few days to think about this and I still don't get what you mean. Sarcasm or sage advice? Maybe you could expland this a little?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

      That wasn't sarcasm. I meant that if you mean to flatten a multi-level key into a string you find out the maximum length of each key component (or truncate and pad) and join them together in the proper order after padding. I include both a Lotus Domino @Formula and some perl code because I find both to be really, really typical. The Lotus Domino code is a bit simpler because the sorting is actually occuring just outside of this snippet in a View so all you see here is the serialization of a single record's keys.

      REM { Sorting by three values for Lotus Domino (in a single view colum +n). } MaxLength := 255; @Implode( @Transform( A : B : C; "key"; @If( @Length( key ) > 255; @Left( key; MaxLength ); key + @Repeat( @Char( 0 ); MaxLength - @Length( key ) ) )
      # Sorting a three level hash in perl my $a_len = max( map length(), keys %h ); my $b_len = max( map length(), map keys %$_, values %h ); my $c_len = max( map length(), map keys %$_, map values %$_, values %h ); my $fmt = "a$a_len a$b_len a$c_len"; # Assumes \0 is not present in any keys my @sorted_keys = ( map [ unpack( "a$a_len a$b_len a$c_len ", $_ ) ], sort map( { my $a = $_; map( { my $b = $_; map( { pack( "a$a_len a$b_len a$c_len", $a, $b $_ ) } keys %{ $h{ $a }{ $b } } ) } keys %{ $h{ $a } } ) } keys %h );

        Okay. That's what I did for the standard GRT version.

        What confused me is I was trying to see how to apply that when using Sort::Maker. I still can't work out what code to put where, in order to have that module generate the GRT (or ST) for me, for a sort of this complexity.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found