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

Re^3: Converting HoA into HoH

by Zaxo (Archbishop)
on Oct 31, 2005 at 07:21 UTC ( #504184=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^4: Converting HoA into HoH
by neversaint (Deacon) on Oct 31, 2005 at 07:53 UTC
    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
Node Status?
node history
Node Type: note [id://504184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-06-06 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (41 votes). Check out past polls.

    Notices?