Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Get total number of characters in a hash (not memory usage)

by tybalt89 (Monsignor)
on Jan 29, 2020 at 18:20 UTC ( [id://11112035]=note: print w/replies, xml ) Need Help??


in reply to Re: Get total number of characters in a hash (not memory usage)
in thread Get total number of characters in a hash (not memory usage)

Handles any nesting of [] and {}

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11111985 use warnings; use List::Util qw( sum0 ); my $orders = [ { 'OrderDate' => '2019-11-01 00:00:00', 'AlternateKey' => 'D', 'Customer' => '1238756', 'SalesOrder' => '10928', 'CustomerName' => 'Dunder Mifflin', 'ShippingInstrs' => 'Standard' }, { 'OrderDate' => '2020-01-15 00:00:00', 'SalesOrder' => '11349', 'Customer' => '1239451', 'AlternateKey' => 'R', 'CustomerName' => 'Vance Refrigeration', 'ShippingInstrs' => 'Standard' }, { 'OrderDate' => '2020-01-22 00:00:00', 'SalesOrder' => '12954', 'Customer' => '1240029', 'AlternateKey' => 'R', 'CustomerName' => 'A1A Car Wash', 'ShippingInstrs' => 'Next Day' } ]; sub charcount { my $tree = shift; ref $tree or return length $tree; sum0 map charcount($_), ref $tree eq 'HASH' ? %$tree : @$tree; } print charcount($orders), "\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-26 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found