Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Hash Manipulationby Fletch (Bishop) |
on Jun 07, 2021 at 18:41 UTC ( [id://11133635]=note: print w/replies, xml ) | Need Help?? |
This may sound a bit like pushing you out into deeper water, but you probably should look into the Template module (see also template-toolkit.org). Rather than trying to whip up your formatted data in your hash, concentrate on extracting just the info you want to appear in your output and pass that to a template which has placeholders in your TeX output. That lets you separate manipulating your data from the presentation (and the template lets you more easily get the output in the right "shape" and you just have to pass the right things to populate the placeholders).
Edit: Two things came to mind after seeing haukex' reply below: I didn't look closely at your manipulation code (because what you're trying to do made my eyes water . . .) but he's completely right about you overwriting things reassigning new hashrefs. Similarly using integers as the keys of a hash is a sign you prossibly want a different data structure using an arrayref instead. Using an array(ref) and push would maybe make some of your problems with tracking the indexen and positions easier. Checkout the data structures cookbook for more details (perldsc; look for an AoH, Array Of Hashes). Also another TT feature that may be of use is the loop special variable that gives you access to an iterator object inside the template FOR loop (added a comment using it to sample above). You could use that and arithmetic to alter the output based on which element you're on to get your pagination / special breaks. Alternately you could use something like List::MoreUtils and its natatime to partition your list into whatever size chunks.
The cake is a lie.
In Section
Seekers of Perl Wisdom
|
|