-
Notifications
You must be signed in to change notification settings - Fork 14
/
PostData.pm
executable file
·91 lines (84 loc) · 2.83 KB
/
PostData.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package PostData;
#----------------------------------------------------------#
# Copyright (C) 1997 Washington University, St. Louis, MO. #
# All Rights Reserved. #
# #
# Author: Ian Korf #
# Send all comments to ikorf@sapiens.wustl.edu #
# #
# DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" #
# WITHOUT WARRANTY OF ANY KIND. #
#----------------------------------------------------------#
require Exporter;
@PostData::ISA = qw(Exporter);
@EXPORT = qw(PostData);
use Term::ANSIColor;
use strict;
=head1 NAME PostData
=cut
#----------------------------------------------
# PostData - output simple data structures
#
# Prints out a data structure in regular format
# Only follows ARRAY, HASH, and SCALAR
# Does not terminate recursive data structures
#----------------------------------------------
sub PostData {
my ($data,$max,$level) = @_;
$level = 1 unless defined $level;
$max = 100 unless defined $max;
my ($i,$key,$value);
my $tab = " " x $level;
my $ref = ref($data);
if (not $ref) {
if (defined $data) {print "$data\n"}
else {print "UNDEFINED VALUE\n"}
}
elsif ($ref eq 'SCALAR') {
print "$ref\n";
return if $max == $level;
print $tab,"$$data\n";
}
elsif ($ref eq 'ARRAY') {
print "$ref\n";
$level++;
return if $max == $level;
for($i=0;$i<@$data;$i++) {
print $tab,"[$i] = ";
PostData($data->[$i],$max,$level);
}
}
elsif ($ref eq 'REF') {
print "$ref\n";
$level++;
return if $max == $level;
PostData($$data,$max,$level);
}
elsif ($ref eq 'HASH') {
print "$ref\n";
$level++;
return if $max == $level;
foreach $key (sort keys %$data) {
print $tab,"{$key} = ";
PostData($data->{$key},$max,$level)
}
}
#--- MY hack
elsif ($ref eq 'FileHandle'){
print "$ref\n";
}
#--- end
elsif ($ref ne 'CODE') {
print "$ref \n";
$level++;
return if $max == $level;
foreach $key (sort keys %$data) {
print $tab,"{$key} = ";
PostData($data->{$key},$max,$level)
}
}
else {
print "$ref not handled by PostData\n";
}
}
1;