Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Term::ReadKey in .bashrc command script

I'm writing a simple motd-script in perl, that parses messages from specific websites and displays them in the center of the terminal screen.

To get the width of the terminal I use the CPAN module Term::ReadKey.
Now I am calling this script with

command /path/to/script

from my .bashrc to display it on login and opening a terminal.

My script works fine when called while I'm logged in via perl or using

source .bashrc

but on the initial opening of a terminal (which is the actual purpose of the script) I'm getting this Error message:

Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at /path/to/perl-motd.pl line 6.
BEGIN failed--compilation aborted at /path/to/perl-motd.pl line 6.

Line 6 of the script is

use Term::ReadKey;
like image 566
Moritz Petersen Avatar asked Dec 20 '22 21:12

Moritz Petersen


1 Answers

First find where that module is installed: locate Term/ReadKey.pm

If it's not found, you have to install it (may require sudo): cpan Term::ReadKey

If it is already installed, you have to tell Perl where it is:

use lib '/path/to';   # assuming it's installed as "/path/to/Term/ReadKey.pm"
use Term::ReadKey;
like image 188
glenn jackman Avatar answered Jan 05 '23 01:01

glenn jackman