Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: split hash into two columns

by sulfericacid (Deacon)
on Mar 27, 2006 at 20:42 UTC ( [id://539535]=note: print w/replies, xml ) Need Help??


in reply to split hash into two columns

Here is my attempt without using arrays. Note this doesn't break them into two columns (it sort of almost does, it prints the first half and then the second half), but it's the best I could do. Maybe you could figure out how to hack it to do what you want. It'd actually be interesting to see if someone can fix my almost functional code.
my $half = scalar keys %hash; $half = $half / 2 + 1; my $cnt = 0; foreach (keys %hash) { $cnt++; my $key = $_; if ($cnt <= $half) { print "$key => $hash{$key}\n"; } else { print "\t$key => $hash{$key}\n"; } }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re^2: split hash into two columns
by ikegami (Patriarch) on Mar 27, 2006 at 20:52 UTC
    It'd actually be interesting to see if someone can fix my almost functional code

    It's still quite far off. davidrw's earlier solution (and the fix I added in my reply) is the what you get if you continue on your path.

      Yes, I thought about that uninitialized error and knew that would come up. By golly, if I can't come up with a dirty hack to do a pure hash solution I'm going to go crazy.

      I'll make another attempt if I can come up with something.



      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found