Term::ReadKey in .bashrc command script

14,580

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;
Share:
14,580
Moritz Petersen
Author by

Moritz Petersen

Updated on June 04, 2022

Comments

  • Moritz Petersen
    Moritz Petersen almost 2 years

    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;
    
  • Moritz Petersen
    Moritz Petersen over 10 years
    Thank you - it worked! I guess it wasn't found because my Perl-path exports are at the end of my .bashrc - simple :)