Bug 4161: Preselect active currency for new vendors
[koha.git] / C4 / Utils.pm
blobad38397ed5f0f66a620fbbf085d7a4170bb49c81
1 package C4::Utils;
3 # Useful code I didn't feel like duplicating all over the place.
6 use strict;
7 use warnings;
8 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
10 BEGIN {
11 require Exporter;
12 $VERSION = 1.00; # set the version for version checking
13 $debug = $ENV{DEBUG} || 0;
14 @ISA = qw(Exporter);
15 @EXPORT_OK = qw(&maxwidth &hashdump);
16 %EXPORT_TAGS = ( all => [qw(&maxwidth &hashdump)], );
20 sub maxwidth (@) {
21 (@_) or return 0;
22 return (sort {$a <=> $b} map {length} @_)[-1];
25 sub hashdump ($$) {
26 my $pre = shift;
27 my $val = shift;
28 if (ref($val) =~ /HASH/) {
29 print "$pre = HASH w/ " . scalar(keys %$val) . " keys.\n";
30 my $w2 = maxwidth(keys %$val);
31 foreach (sort keys %$val) {
32 &hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $val->{$_});
34 print "\n";
35 } elsif (ref($val) =~ /ARRAY/) {
36 print "$pre = ARRAY w/ " . scalar(@$val) . " members.\n";
37 my $w2 = maxwidth(@$val);
38 foreach (@$val) {
39 &hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $_);
41 print "\n";
42 } else {
43 print "$pre = $val\n";
48 __END__