Putting It All Together

This section goes through the design and implementation of a real-world program. The assignment is to come up with a pattern-searching program called tk_grep.pl.

The GUI for this program was shown earlier (refer to Figure 13.4).

The user specifies a regular expression in the Pattern box and a set of files in the Files box and then clicks on Search to search all the files for the given pattern. The results are shown in a pop-up window.

First, you need a main window:

my $tk_mw = MainWindow–>new();

Next, you construct the main GUI. The top two widgets are a label for the Pattern string and an Entry for the pattern itself. You also need a frame in which to put them.

So create the frame and the two widgets. First the frame: ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.