Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

require Readline - You cannot create an instance of this type (Readline) [duplicate]

When I run this code

require Readline;
my $rl = Readline.new;
my $string = $rl.readline( ':');
$string.say;

I get this error-message:

You cannot create an instance of this type (Readline)

When I use useto load Readline it works. Why does require Readline not work?

like image 770
sid_com Avatar asked May 10 '21 05:05

sid_com


1 Answers

Since require causes the module to be loaded at runtime, the lookup of the Readline symbol must also be deferred until runtime. This can be done using the ::('Type::Name') syntax, as follows:

require Readline;
my $rl = ::('Readline').new;
my $string = $rl.readline( ':');
$string.say;
like image 178
Jonathan Worthington Avatar answered Nov 15 '22 09:11

Jonathan Worthington