>>>>> "JG" == Jim Green <student.northwest...@gmail.com> writes:
JG> On Thu, Mar 3, 2011 at 6:31 PM, Jim Gibson <jimsgib...@gmail.com> wrote: >> On 3/3/11 Thu Mar 3, 2011 3:11 PM, "Jim Green" >> <student.northwest...@gmail.com> scribbled: >> >>> On Mar 3, 5:44 pm, shawnhco...@gmail.com (Shawn H Corey) wrote: >>>> On 11-03-03 05:40 PM, Jim Green wrote: >>>> >>>>> But is there a easier way of >>>>> doing this I might not be aware of? >>>> >>>> Given your brief description, no. The problem is that you can't output >>>> the first datum without reading the last, because the last may be the >>>> first thing that needs to be outputted. >>> >>> Hello, let me generalize this problem, >>> lets say I have a hash with 2 levels of keys, >>> I want to convert this hash to another hash but with the 2 levels of >>> keys reversed.. I hope there is a module or sth that can do it. >> >> That is a simple problem that doesn't need a module (although one may >> exist). >> >> Untested: >> >> my %oldhash = ( a => { b=>c, d=>e }, f => {g=>h, i=>j}, ... ); >> my %newhash; >> for( my($key1,$val1) = each %oldhash ) { >> for( my($key2,$val2) = each %{$val1} ) { >> $newhash{$key2}->{$key1} = $val2; >> } >> } JG> Thanks Jim, this will definitely work. but changing order of keys is a JG> general problems and hopefull some module exists to do that. hash keys have no order. this is true even when serialized to a string in any format (yaml, dumper, json, etc.). when read back in, the order in the string will be lost in most any lang. so expecting order there is a bad idea. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/