This is first example from perldoc
use Curses::UI;
my $cui = new Curses::UI;
my $win = $cui->add('window_id', 'Window');
my $grid =$win->add(
'mygrid', 'Grid'
-rows => 3,
-columns => 5,
);
# set header desc
$grid->set_label("cell$_", "Head $_")
for (1 .. 5);
# add some data
$grid->set_cell_value("row1", "cell$_", "value $_")
for 1 .. 5;
my $val = $grid->get_value("row1", "cell2");
which gives me this fatal eror
Fatal program error:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Could not load Curses::UI::0 from Curses/UI/0.pm:
Can't locate Curses/UI/0.pm in #INC (#INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/sha
re/perl/5.10 /usr/local/lib/site_perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 .) at /usr/share/perl5/Curses/UI.pm line 846.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Press any key to exit...
How should I resolve this?
Ok, I've got this fixed on my machine. You need to install the following packages:
sudo cpan -fi Curses::UI::Widget
sudo cpan -fi Curses::UI::Grid
If you already did install them as well, you should try it again, because I also thought that I installed them, but eventually it appeared that I did not do it properly at first and I've got the same errors as you did. Now everything works, hope it will help you.
Related
I would like to conditional load a package if the program name is a test script ending in .t.
However, I'm running into a bug where use if fails when the condition is a regex. I've tested this in Perl 5.10 and 5.16.
The following is my test script ending in .t:
#!/usr/bin/env perl
use v5.10;
BEGIN { say "\$0 is '$0'" }
use if $0 =~ /\.t\z/, 'List::Util', ('pairmap');
say "List::Util is " . ( $INC{"List/Util.pm"} ? '' : 'NOT ' ) . 'included';
Outputs:
$ ./test.t
$0 is './test.t'
List::Util is included
However, the same file with a .pl extension fails:
$ ./test.pl
$0 is './test.pl'
Can't locate pairmap.pm in #INC (#INC contains: /usr/lib64/perl5/5.10.0 /usr/lib64/perl5 /usr/local/share/perl5/x86_64-linux-thread-multi /usr/local/share/perl5 /usr/local/lib64/perl5 /usr/share/perl5 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/share/perl5/if.pm line 13.
BEGIN failed--compilation aborted at ./test.pl line 7.
I can coerce the code into working if I double bang the regex or change it to a substr comparison:
use if !!( $0 =~ /\.t\z/ ), 'List::Util', ('pairmap');
use if substr( $0, -2 ) eq '.t', 'List::Util', ('pairmap');
Outputs:
$ ./test.pl
$0 is './test.pl'
List::Util is NOT included
Is this a known bug? If so, in what version was it fixed?
This is a bug in your code.
The argument list after use MODULE is in, well, list context.
m// in list context returns a list of captured strings if successful (or 1 if the regex contains no capturing groups), or the empty list on failure.
Thus:
use if "test.pl" =~ /\.t\z/, 'List::Util', ('pairmap');
is equivalent to
use if (), 'List::Util', ('pairmap');
(The match failed, so an empty list is returned.)
, in list context is the list concatenation operator, so this gives:
use if 'List::Util', 'pairmap';
'List::Util' is a true value, so this ultimately ends up loading pairmap.pm:
use pairmap;
The fix is to give the match scalar context:
use if scalar($0 =~ /\.t\z/), 'List::Util', 'pairmap';
(! also supplies scalar context to its operand, so !! has the same effect.)
I am trying to read data from excel, i have below code.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use feature 'say';
use Spreadsheet::XLSX;
use Spreadsheet::Read qw(ReadData);
my $book = ReadData ('/tmp/simple.xlsx');
say 'A1: ' . $book->[1]{A1};
my #row = Spreadsheet::Read::row($book->[1], 1);
for my $i (0 .. $#row) {
say 'A' . ($i+1) . ' ' . ($row[$i] // '');
}
my #rows = Spreadsheet::Read::rows($book->[1]);
foreach my $i (1 .. scalar #rows) {
foreach my $j (1 .. scalar #{$rows[$i-1]}) {
say chr(64+$i) . " $j " . ($rows[$i-1][$j-1] // '');
}
}
getting the error as:
Can't locate OLE/Storage_Lite.pm in #INC (#INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Spreadsheet/ParseExcel.pm line 21.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Spreadsheet/ParseExcel.pm line 21.
Compilation failed in require at /usr/local/share/perl5/Spreadsheet/XLSX.pm line 14.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Spreadsheet/XLSX.pm line 14.
Compilation failed in require at read_excel.pl line 6.
BEGIN failed--compilation aborted at read_excel.pl line 6.
I have every related module. but as per error when i am going to download OLE/Storage_Lite.pm from the CPAN, page is going blank, and from metacpan below error is coming.
https://cpan.metacpan.org/authors/id/M/MS/MSCHWARTZ/OLE-Storage-0.386.tar.gz
Resolving cpan.metacpan.org... 151.101.128.249, 151.101.192.249, 151.101.64.249, ...
Connecting to cpan.metacpan.org|151.101.128.249|:443... connected.
ERROR: certificate common name “a.ssl.fastly.net” doesn’t match requested host name “cpan.metacpan.org”.
To connect to cpan.metacpan.org insecurely, use ‘--no-check-certificate’.
Try downloading the module tar zip from cpan or metacpan. Then build the module locally using any make utility(e.g.dmake). You can find more info for building module locally from here.
I try to create a perl tool for processing tweets with regex.
My problem is that I can not retrieve tweets from the update to version 1.1 in the twitter API
Here is the error that the terminal returns :
Can't locate Net/Twitter/Role/API/RESTv1_1.pm in #INC
(#INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .)
at /usr/share/perl5/Module/Runtime.pm line 205
I use this documentation :
https://metacpan.org/module/MMIMS/Net-Twitter-4.00003/lib/Net/Twitter/Manual/MigratingToV1_1.pod#Include-the-API::RESTv1_1-trait
Here is my code :
#!/usr/bin/perl -w
use Net::Twitter;
use Scalar::Util 'blessed';
use Data::Dumper;
my $nt = Net::Twitter->new(
traits => [qw/API::RESTv1_1/],
consumer_key => "my_key1",
consumer_secret => "my_key2",
access_token => "my_key3",
access_token_secret => "my_key4",
);
my #t = $nt->search('hello');
print Dumper #t;
Can you help me ? What did I do wrong ?
Thanks, F.
Probably because you have an old version of Net::Twitter installed. Support for API1.1 was added in version 4.0.
How to install all dependencies of the module Nmap::Scanner with cpan in Perl? I did, cpan Nmap::Scanner. But, needing other dependencies for module.
#!/bash/perl
use Nmap::Scanner;
my $scan = Nmap::Scanner->new();
$scan->add_target('localhost');
$scan->add_target('host.i.administer');
$scan->add_scan_port('1-1024');
$scan->add_scan_port('31337');
$scan->tcp_syn_scan();
$scan->noping();
my $results = $scan->scan();
my $hosts = $results->gethostlist();
while (my $host = $hosts->get_next()) {
print "On " . $host->hostname() . ": \n";
my $ports = $host->get_port_list();
while (my $port = $ports->get_next()) {
print join(' ',
'Port',
$port->service() . '/' . $port->portid(),
'is in state',
$port->state(),
"\n"
);
}
}
I did, but when running the script in perl, shows this in console.
Can't locate XML/SAX/Exception.pm in #INC (#INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl` /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/XML/SAX/ParserFactory.pm line 12.
BEGIN failed--compilation aborted at /usr/local/share/perl5/XML/SAX/ParserFactory.pm line 12.
Compilation failed in require at /usr/local/share/perl5/Nmap/Scanner/Backend/XML.pm line 8.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Nmap/Scanner/Backend/XML.pm line 8.
Compilation failed in require at /usr/local/share/perl5/Nmap/Scanner/Scanner.pm line 4.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Nmap/Scanner/Scanner.pm line 4.
Compilation failed in require at /usr/local/share/perl5/Nmap/Scanner.pm line 10.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Nmap/Scanner.pm line 10.
Compilation failed in require at e1-insecure.pl line 3.
BEGIN failed--compilation aborted at e1-insecure.pl line 3.
cpan resolves dependencies automatically. To install execute the following command:
cpan Nmap::Scanner
An alternative installer for CPAN modules is cpanminus. Using cpanm:
cpanm Nmap::Scanner
This question already has answers here:
What's the easiest way to install a missing Perl module?
(24 answers)
Closed 7 years ago.
I have Solaris 10,i am trying to run a Perl program.
I have two perl versions installed:
/usr/bin/perl of version 5.8.4
and
/usr/local/bin/perl of version 5.12.3
I have installed the DBI package (it got installed here, /usr/perl5/site_perl/5.8.4/sun4-solaris-64int/auto/DBI/.packlist),the problem I get by executing the Perl program with different perl version is (In ubuntu its working fine).
bash-3.00# perl temp.pl
Can't locate Time/Piece.pm in #INC (#INC contains: /usr/perl5/5.8.4/lib/sun4-
solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int
/usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-
solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at
temp.pl line 4.
BEGIN failed--compilation aborted at temp.pl line 4.
bash-3.00# /usr/local/bin/perl temp.pl
Can't locate DBI.pm in #INC (#INC contains: /usr/local/lib/perl5/site_perl/5.12.3
/sun4-solaris /usr/local/lib/perl5/site_perl/5.12.3 /usr/local/lib/perl5/5.12.3/sun4-
solaris /usr/local/lib/perl5/5.12.3 /usr/local/lib/perl5/site_perl .) at temp.pl line5.
BEGIN failed--compilation aborted at temp.pl line 5.
I have tried hell lot of ways but not getting how to run my Perl program on solaris.
Could anybody help please.
Below is my program. In fact it was redefined by #Borodin. Thanks a lot to him.
use strict;
use warnings;
use Time::Piece;
use DBI;
open my $log, '<', '/opt/testlogs/test.log' or die "Unable to open log file: $!";
my ( $count_start, $count_interim, $count_stop ) = ( 0, 0, 0 );
while (<$log>) {
if (/server start/) {
$count_start++;
}
elsif (/server interim-update/) {
$count_interim++;
}
elsif (/server stop/) {
$count_stop++;
}
}
print <<END;
Start: $count_start
Interim: $count_interim
Stop: $count_stop
END
print localtime->strftime("%b %e %H:%M:%S"), "\n";
my $dbh = DBI->connect( "DBI:Pg:dbname=postgres;host=localhost", "postgres", "postgres", { 'RaiseError' => 1 } );
my $rows = $dbh->do(
"insert into radius (server_start, server_stop, server_interim)
Values ($count_start, $count_stop, $count_interim)"
);
printf "%d %s affected\n", $rows, $rows == 1 ? 'row' : 'rows';
You don't have Time::Piece installed for /usr/bin/perl, so install it.
/usr/bin/perl -MCPAN -e install Time::Piece
You don't have DBI installed for /usr/local/bin/perl, so install it.
/usr/local/bin/perl -MCPAN -e install DBI