Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: Converting HoA into HoH

by neversaint (Deacon)
on Oct 31, 2005 at 07:53 UTC ( #504186=note: print w/replies, xml ) Need Help??


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

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.......

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

    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://504186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-06-06 20:42 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?