Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: prettyfy hashes

by BrowserUk (Patriarch)
on Apr 03, 2016 at 02:13 UTC ( [id://1159400]=note: print w/replies, xml ) Need Help??


in reply to prettyfy hashes

#! perl -sw use strict; use List::Util qw[ max ]; my $first = <>; my @ugly = <>; my $last = pop @ugly; my @bits = map[ m[(^\s+)(\S+)\s*=>\s*(\S+),\n] ], @ugly; my $largest = max( map{ length( $_->[1] ) } @bits ); print $first; printf "%s%-${largest}s => %s,\n", @$_ for @bits; print $last;

Output:

C:\test>1159396 C:\test>1159396 %some_hash = ( key => "value1", larger_key => "value2", even_larger_key => "value3", ); ^Z %some_hash = ( key => "value1", larger_key => "value2", even_larger_key => "value3", );

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found