IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Printing out hashes of arrays - best practice?
If I've got a HoA, what's the best way of printing it out? I'm concerned about two things: speed (it's conceivable that said hash is quite large) and flexibility of output (I'm not using Perl reports at the moment, but I might do in the future).

At present, I'm doing what I thought was the simplest thing to get a HoA printed out with each element of each array on a line by itself:
\nforeach $member(@{$groups{$group}})\n{\n  print "$member\\n";\n}


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New How large is large?
Personally I tend to use Data::Dumper. (I prefer setting $Data::Dumper::Indent to 1.) Admittedly that is slow and memory wasteful for data structures with tens of thousands of elements.

Some people prefer the output of YAML. I haven't used it though.

Either will dump a hash of arrays in a readable format, and won't break if your data structure isn't quite as regular as you thought.

Beyond that, if you are going to write your own code for dumping a hash of arrays, I would strongly recommend indenting the array elements some and outdenting the hash keys so that visual scan can tell you where you are in the data structure.

Cheers,
Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Re: How large is large?
While each array might only have a few (<100) elements, there might be lots of arrays (thousands). I'll look at Data::Dumper.


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
     Printing out hashes of arrays - best practice? - (pwhysall) - (2)
         How large is large? - (ben_tilly) - (1)
             Re: How large is large? - (pwhysall)

No, no. We have to provide potential hostages over there so they won’t look for potential hostages over here.
71 ms