GUI Programming in FreeBSD with Perl/Tk

freebsd gui perl tk

What is Perl?

Perl officially stands for Practical Extraction and Report Language.
Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier.it was optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It’s widely used for everything from quick “one-liners” to full-scale application development. Its general-purpose programming facilities support procedural, functional, and object-oriented programming paradigms, making Perl a comfortable language for any purpose.

What is CPAN?

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors.
You can easily add a new library to Perl with cpan that going to make programming easier.
How to deal with CPAN in FreeBSD 11?
cpanminus is Perl extension to get, unpack, build, and install modules from CPAN.to install cpanminus issue this commands:
# pkg install p5-App-cpanminus
# rehash
after that, you can install CPAN module with cpanm command.

What is TK?

The Perl/Tk module, also known as pTk or ptk, is a Perl module designed to create widgets and other commonly used graphical objects to form a graphical user interface (GUI). Using the module to create a GUI enhances the look and feel of a program and helps the end-user navigate through the program and its functions. One major advantage of using the Perl/Tk module is that the resulting application can be cross-platform, meaning the same GUI application can be used on UNIX®, Linux®, Macintosh, Microsoft® Windows®, or any other operating system that has Perl and the Perl/Tk module installed.
Install Tk On FreeBSD
Installation process is very straightforwad and fast and cpanm will take care of everythings.just issue this command:
# cpanm Tk
and Tk is installed successfully.

Create First GUI Application

It’s time to write first gui program in Perl/Tk or PTk .create a file named ptk.pl, and enter the following text in the file:
#!/usr/bin/perl -w
#this is bsdmag ptk tutorial
use Tk;
use strict;
my $mw = MainWindow->new;
$mw->geometry(“200x100”);
$mw->title(“bsdmag!!!”);
$mw->Label(-text => ‘bsdmag’)->pack();
$mw->Button(-text => “Exit”, -command =>sub{exit})->pack();
MainLoop;

You can get full edition at:
https://bsdmag.org/download/nearly-online-zpool-switching-two-freebsd-machines/
Or:
https://contents.meetbsd.ir/ebook/PTk_bsdmag.pdf


enter image description here