1 #! /usr/bin/perl
2
3 use Tk;
4 use Tk::NoteBook;
5
6 $num_adapters = 0;
7 $adapt_tabs = 0;
8 $inter = 0;
9 $inter2 = 0;
10 $count2;
11 $adapt_tabs = 0;
12 $num1;
13 @interface[$num1];
14 $s1=0;
15 $page_num = 0;
16
17 # Create MainWindow
18
19 $win_main = MainWindow->new(-background => 'black');
20 $win_main->title ("IP Configuration");
21 $win_main->geometry("350x150+0+0");
22
23 #Add Notebook Widget to the main window
24 $nb = $win_main->NoteBook();
25
26 #Run ipconfig command and put results into the @list array
27 @list = `ipconfig /all`;
28
29 #Walk through the information in the @list array and
30 #make a page for host information
31 foreach (@list) {
32
33 if (/Host/) {
34 ($label,$value) = split /:/;
35 $title = "Host: " . $value;
36 $host_tab = $nb->add("Host", -label => $title);
37 }
38 # Count the number of adapters, parse the name and add the name to
+the
39 # @interface array
40
41 if (/Ethernet adapter/) {
42
43 $int_name = $_;
44 $int_name =~ s/Ethernet adapter//;
45 $int_name =~ tr/://d;
46 chop $int_name; chop $int_name;
47 @interface[$num1] = $int_name;
48 $num1++;
49 $num_adapters++;
50 }
51 }
52
53 # Create a page for each interface
54
55 foreach (@interface) {
56 $page_name = $_;
57 #$lname = "a" . $s1;
58 $int[$s1] = $nb->add($s1, -label => $page_name);
59 $s1++
60 }
61
62 #Print page names
63
64 @pn = $nb->pages;
65 foreach (@pn) {
66 print $_ . "\n";
67 }
68
69 # Process the information onto the pages
70
71 foreach (@list) {
72
73 ($lab1,$val1) = split /:/;
74 $lab_len = length $lab1;
75 $val_len = length $val1;
76 $output = $label . ": " . $value;
77
78
79 if (/Ethernet adapter/) {
80 $nb->$page_num->Label(-textvariable => $output)->pack();
81 $page_num++;
82 }
83 else {
84 $nb->$page_num->Label(-textvariable => $output)->pack();
85 }
86 }
87
88 $win_main->pack(-side => 'left', -anchor => 'nw');
89
90
91 MainLoop;
The problem I am having is lines 80 and 84. When I run the script I get the following error:
So my question is how do I address a "page" in the NoteBook and add things like Labels or text?