Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

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

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 );

In reply to Re^5: To use a module...or not. by diotalevi
in thread To use a module...or not. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2023-03-30 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (74 votes). Check out past polls.

    Notices?