package PrettyPrinting; # the .pm file extension is required require Exporter; # load at run time our @ISA = qw(Exporter); # inherits from the Exporter package our @EXPORT = qw(print_tree); # export by default our @EXPORT_OK = qw(print_indent print_scalar); # export by request my $depth = -1; sub print_indent { my $spaces = ". " x $depth; print $spaces, shift, "\n"; } sub print_scalar { ++$depth; my $obj = shift; print_indent $obj; --$depth; } sub print_tree { my ($r_array) = @_; ++$depth; print_indent "(" . shift @{$r_array}; foreach my $obj (@{$r_array}) { if (ref ($obj)) { print_tree($obj); }else{ print_scalar($obj); } } print_indent ")"; --$depth; } 1; # the return value of the module, mandatory