I have the following Perl code that relies on Term::ReadKey to get the width of the terminal; This module is missing in my NetBSD assembly, so I want to use the default terminal width to 80 when the module is missing.
I cannot understand how to conditionally use a module, knowing in advance whether it is available. My current implementation simply terminates with a message saying that it cannot find Term::ReadKey if it is missing.
#/usr/pkg/bin/perl -w # Try loading Term::ReadKey use Term::ReadKey; my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(); my @p=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97); my $plen=$#p+1; printf("num |".("%".int(($wchar-5)/$plen)."d") x $plen."\n",@p);
I use Perl 5.8.7 on NetBSD and 5.8.8 on CygWin. Can you help me implement this in my script more efficiently?
module perl
dlamblin Oct 30 '08 at 20:41 2008-10-30 20:41
source share