Leser: 1
![]() |
|< 1 2 3 >| | ![]() |
30 Einträge, 3 Seiten |
1
2
my %switches = (switch0 => [qw/switch1 switch2 switch3/],
switch1 => [qw/switch4/],);
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
#!/usr/bin/perl
use strict;
use warnings;
my %switches = (switch0 => [qw/switch1 switch2 switch3/],
switch1 => [qw/switch4/],);
my $start = 'switch0';
print_tree(\%switches,$start,0);
sub print_tree{
my ($hashref,$start,$level) = @_;
my $whitespaces = ' ' x ($level * 5);
print $whitespaces.$start,"\n";
for my $switch(@{$hashref->{$start}}){
if(exists $hashref->{$switch}){
print_tree($hashref,$switch,$level+1);
}
else{
my $whitespaces = ' ' x (($level+1) * 5);
print $whitespaces.$switch,"\n";
}
}
}
1
2
3
4
5
6
7
digraph Switches {
nodesep=0.7
switch0 -> switch1
switch0 -> switch2
switch0 -> switch3
switch1 -> switch4
}
![]() |
|< 1 2 3 >| | ![]() |
30 Einträge, 3 Seiten |