I'd generally pass around an indentation string, along these lines:
use strict;
sub main {
my ($strings, $indent) = @_;
$indent = "" unless defined $indent;
print $indent, shift(@$strings), "\n";
nested($strings, $indent."\t");
}
sub nested {
my ($strings, $indent) = @_;
$indent = "" unless defined $indent;
print $indent, shift(@$strings), "\n";
deep($strings, $indent."\t");
}
sub deep {
my ($strings, $indent) = @_;
$indent = "" unless defined $indent;
print $indent, shift(@$strings), "\n";
}
my @list = qw(main nested deep);
main(\@list);
A similar technique is to pass around an indent level as an integer, incrementing it as needed:
use strict;
sub main {
my ($strings, $indent) = @_;
$indent = 0 unless defined $indent;
print "\t" x $indent, shift(@$strings), "\n";
nested($strings, $indent+1);
}
sub nested {
my ($strings, $indent) = @_;
$indent = 0 unless defined $indent;
print "\t" x $indent, shift(@$strings), "\n";
deep($strings, $indent+1);
}
sub deep {
my ($strings, $indent) = @_;
$indent = 0 unless defined $indent;
print "\t" x $indent, shift(@$strings), "\n";
}
my @list = qw(main nested deep);
main(\@list);