#!/usr/bin/perl use warnings; use strict; use Math::BigInt; use Tk; sub factorial { my ($n) = @_; return 1 if $n == 0; no warnings 'recursion'; return factorial($n-1) * $n } my $mw = MainWindow->new(-title => 'Factorial Calculator'); my $result; my $value; my $v = $mw->Entry( -width => 6, -relief => 'sunken', -textvariable => \$value, ); my $calculate = sub { # Stringify to prevent the conversion to int or float! $result = "" . factorial(Math::BigInt->new($value)); }; $v->bind('', $calculate); my $desc = $mw->Label(-text => 'Factorial is:',); my $r = $mw->Label(-textvariable => \$result,); my $calc = $mw->Button(-text => 'Calculate', -command => $calculate); my $q = $mw->Button(-text => 'QUIT', -command => sub { $mw->DESTROY },); Tk::grid($v, $desc, $r, -padx => 10, -pady => 10); Tk::grid($calc, '-', '-', -padx => 10, -pady => 5); Tk::grid($q, '-', '-', -padx => 10, -pady => 5); Tk::MainLoop();