Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Converting HoA into HoH

by neversaint (Deacon)
on Oct 31, 2005 at 06:35 UTC ( [id://504175]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting HoA into HoH
in thread Converting HoA into AoH

Dear Zaxo,
Thanks also for your response. Two points here. Why your subroutine above takes 2 arguments as input?

Another point is, I tried your code,
my $ref = hoa2aoh($HoA); print Dumper $ref;
it returns:
$VAR1 = [ { 'flintstones' => undef, 'jetsons' => 'george' }, { 'flintstones' => undef, 'jetsons' => 'jane' } ];
Please correct me if I misinterpret how your function works.

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re^3: Converting HoA into HoH
by Zaxo (Archbishop) on Oct 31, 2005 at 07:21 UTC

    I had an error in the argument to glob, repaired as noted above.

    The superfluous variable was $hoh in the line

    my ($hoa, $hoh) = shift;
    That doesn't really involve two arguments - the shift only brings in one value, and $hoh remained undefined and unused. I only thought I'd want it at first, and piggybacked its declaration on the arg line.

    After Compline,
    Zaxo

      Dear Zaxo,
      One last thing here. I'm really sorry for not being precise earlier. I was just trying to pose the problem as simple as possible. The element of the array in my actual production code comes with white space like this:
      my $HoA = { '1,2,flintstones' => [ "fred-1 foo-2", "barney-1 bar-2" ], '2,3,jetsons' => [ "george-1 foo-2", "jane-1 bar-2"], };
      The key of the new hash is identified correctly, the problem is only in the values. Is there a way I can modify your code? In particular, so that it takes the element of the array as "one" entity regardless the white-space?
      So that it doesn't return:
      $VAR1 = [ { '1,2,flintstones' => undef, '2,3,jetsons' => undef }, { '1,2,flintstones' => 'jane-1', '2,3,jetsons' => 'foo-2' }, { '1,2,flintstones' => undef, '2,3,jetsons' => 'bar}' }, { '1,2,flintstones' => 'barney-1', '2,3,jetsons' => 'foo-2' }, { '1,2,flintstones' => undef, '2,3,jetsons' => 'bar-2}' } ];
      But simply:
      my $AoH = [ { '1,2,flinstones' => "fred-1 foo-2", '2,3,jetsons' => "george-1 foo-2" }, { '1,2,flinstones' => "fred-1 foo-2", '2,3,jetsons' => "jane-1 bar-2" }, { '1,2,flinstones' => "barney-1 bar-2", '2,3,jetsons' => "george-1 foo-2" }, { '1,2,flinstones' => "barney-1 bar-2", '2,3,jetsons' => "jane-1 bar-2" }, ];
      I tried to modify your code by changing the type of separator. But doesn't work either. Hope to hear from you again.

      ---
      neversaint and everlastingly indebted.......

        The problem is the same one I had with spaces in the glob. I'll post a working rewrite at top level. The only difference is to insert an escape '\' before each space. If your real data contains other things to mess up glob, treat similarly.

        After Compline,
        Zaxo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-19 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found