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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Is there a way of displaying it in the order it came in without using Tie::IxHash module. That is not on my system and will have to put in a ticket to have the module installed.

Do you have to have a ticket to install your code on your machine?

Copy & paste the code into your own source file; and tell the controlling powers that you've done so.

As you can see - the results are unordered.

That is the nature of hashes. The use-cases for hashes don't require (or benefit) from them being ordered. Humans like things ordered, but programs don't give a damn.

And if all you want to do is present the same information back to the users in the same form, just print the file to their screen.

But if you really must remember the order, just make a note of it as you go:

#! perl -slw use strict; my %ini; my( $product, $feature ); while( <DATA> ) { chomp; if( /\s+(\S+)=(\S+)/ ) { $ini{ $product // die "Malformed ini at:$." } { $feature // 'none' } { $1 } = $2; push @{ $ini{ $product }{ $feature // 'none' }{ order } }, $1; } elsif( /^PROD/ ) { push @{ $ini{ $product }{ order } }, 'none' if $product and not exists $ini{ $product }{ order }; $product = $_; push @{ $ini{ order } }, $product; undef $feature; } else { /^\s+(\S+)/ and $feature = $1; push @{ $ini{ $product }{order} }, $feature; } } for my $product ( @{ $ini{ order } } ) { print $product; for my $feature ( @{ $ini{ $product }{ order } } ) { print "\t", $feature if $feature ne 'none'; for my $type ( @{ $ini{ $product }{ $feature }{ order } } ) { print "\t\t$type=$ini{ $product }{ $feature }{ $type }"; } } } __DATA__ PRODUCT1 FEATURE1_PRODUCT1 PROPERTY1_FEATURE1_PRODUCT1=VALUE1 PROPERTY2_FEATURE1_PRODUCT1=VALUE2 PROPERTY3_FEATURE1_PRODUCT1=VALUE3 PRODUCT2 PROPERTY1_PRODUCT2=VALUE1 PROPERTY2_PRODUCT2=VALUE2 PRODUCT3 FEATURE1_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 PROPERTY2_FEATURE1_PRODUCT3=VALUE2 PROPERTY3_FEATURE1_PRODUCT3=VALUE3 FEATURE2_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 FEATURE3_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 PROPERTY2_FEATURE1_PRODUCT3=VALUE2 PROPERTY3_FEATURE1_PRODUCT3=VALUE3 PRODUCT4 PROPERTY1_PRODUCT4=VALUE1 PROPERTY2_PRODUCT4=VALUE2 PRODUCT5

Produces:

[18:17:59.55] C:\test>junk44 PRODUCT1 FEATURE1_PRODUCT1 PROPERTY1_FEATURE1_PRODUCT1=VALUE1 PROPERTY2_FEATURE1_PRODUCT1=VALUE2 PROPERTY3_FEATURE1_PRODUCT1=VALUE3 PRODUCT2 PROPERTY1_PRODUCT2=VALUE1 PROPERTY2_PRODUCT2=VALUE2 PRODUCT3 FEATURE1_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 PROPERTY2_FEATURE1_PRODUCT3=VALUE2 PROPERTY3_FEATURE1_PRODUCT3=VALUE3 FEATURE2_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 FEATURE3_PRODUCT3 PROPERTY1_FEATURE1_PRODUCT3=VALUE1 PROPERTY2_FEATURE1_PRODUCT3=VALUE2 PROPERTY3_FEATURE1_PRODUCT3=VALUE3 PRODUCT4 PROPERTY1_PRODUCT4=VALUE1 PROPERTY2_PRODUCT4=VALUE2 PRODUCT5

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


In reply to Re^3: Reading Install type config file into hash by BrowserUk
in thread Reading Install type config file into hash by tmurnane

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, 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
  • 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2017-12-16 03:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (448 votes). Check out past polls.

      Notices?