Loading ...
Sorry, an error occurred while loading the content.
 

Unable to stop TreePP from sorting hash in order.

Expand Messages
  • sajohn52
    In the following code I m creating an XML structure from a hash. The problem is that the XML structure always comes out in alphabetically order even when I set
    Message 1 of 2 , Jul 19, 2007
      In the following code I'm creating an XML structure from a hash. The
      problem is that the XML structure always comes out in alphabetically
      order even when I set 'first_order'. Can someone suggeest a way to
      get TreePP to print the XML structure in a user defined order instead
      of alphabetically order?

      use strict ;
      use XML::TreePP;


      my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time()) ;
      my $timestamp = sprintf( "%4d-%02d-%02dT%02d:%02d:%02d", ($year+1900),
      ($mon+1), $mday, $hour, $min, $sec ) ;

      my $h = { Msg => { System => 'TH1'
      , MessageType => '0'
      , ProcessID => '100'
      , TimeStamp => "$timestamp"
      , Source => 'wazzup!'
      }
      } ;

      my $tpp = XML::TreePP->new( ) ;
      $tpp->set( indenting => 3 );
      $tpp->set( first_out =>
      [ 'System', 'MessageType', 'ProcessID', 'Timestamp', 'Source' ] ) ;
      my $xml = $tpp->write($h) ;

      print $xml ;
    • Kawasaki Yusuke
      ... Before version 0.20, first_order option have sorted every elements on generating XML. After version 0.20, it now keeps the order given in a array for the
      Message 2 of 2 , Jul 22, 2007
        > I put together the following script to generate an XML from a hash.
        > The problem is that I don't want the XML to be sorted in alphabetacal
        > order. I tried setting the order by using the set 'first_order'
        > option but it doesn't seem to be working. Can suggest a way to get my
        > XML in a user defined order?

        Before version 0.20, first_order option have sorted every elements on
        generating XML.
        After version 0.20, it now keeps the order given in a array for the option.
        last_order option was also changed as the same behavior.
        Try 0.20!

        --
        Kawasaki Yusuke
        http://www.kawa.net/

        On 7/20/07, sajohn52 wrote:
        > I put together the following script to generate an XML from a hash.
        > The problem is that I don't want the XML to be sorted in alphabetacal
        > order. I tried setting the order by using the set 'first_order'
        > option but it doesn't seem to be working. Can suggest a way to get my
        > XML in a user defined order?
        >
        > use strict ;
        > use XML::TreePP;
        >
        >
        > my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time()) ;
        > my $timestamp = sprintf( "%4d-%02d-%02dT%02d:%02d:%02d", ($year+1900),
        > ($mon+1), $mday, $hour, $min, $sec ) ;
        >
        > my $h = { Msg => { System => 'TH1'
        > , MessageType => '0'
        > , ProcessID => '100'
        > , TimeStamp => "$timestamp"
        > , Source => 'wazzup!'
        > }
        > } ;
        >
        > my $tpp = XML::TreePP->new( ) ;
        > $tpp->set( first_out =>
        > [ 'System', 'MessageType', 'ProcessID', 'Timestamp', 'Source' ] ) ;
        > my $xml = $tpp->write($h) ;
        >
        > print $xml ;
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.