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
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've been working on Cassandra from the past two weeks and am stuck in a few places i was hoping you could help me out with it.
I've installed the apache-cassandra-2.0.1,perlcassa-master,Perl5.10, Thrift::XS and Time::HiRes.I am still not able to connect to Cassandra .when i run perl Makefile.PL i get the follow warning
"Warning: prerequisite Class::Accessor 0 not found. Writing Makefile
for perlcassa" Ignoring the warning when i ran my script i got the
following error. "Base class package "Class::Accessor" is empty.
(Perhaps you need to 'use' the module which defines that package
first,or make that module available in #INC (#INC contains:
/usr/local/lib64/perl5 /usr/local/share/perl5
/usr/lib64/perl5/vendor_perl enter code
here/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5
.). at /usr/local/share/perl5/Cassandra/Types.pm line 38 BEGIN
failed--compilation aborted at
/usr/local/share/perl5/Cassandra/Types.pm line 38. Compilation failed
in require at /usr/local/share/perl5/Cassandra/Cassandra.pm line 11.
BEGIN failed--compilation aborted at
/usr/local/share/perl5/Cassandra/Cassandra.pm line 11. Compilation
failed in require at /usr/local/share/perl5/perlcassa/Client.pm line
18. BEGIN failed--compilation aborted at /usr/local/share/perl5/perlcassa/Client.pm line 18. Compilation failed
in require at /usr/local/share/perl5/perlcassa.pm line 159. BEGIN
failed--compilation aborted at /usr/local/share/perl5/perlcassa.pm
line 159. Compilation failed in require at ./cassconn.pl line 2. BEGIN
failed--compilation aborted at ./cassconn.pl line 2."
my script cassconn.pl
#!/usr/bin/perl
use perlcassa;
my $result = $obj->exec(
"SELECT n,ei,toj,sal,d FROM sample.test WHERE n='divya'",
{key_value => 'n'}
);
my $row = $result->fetchone();
print "Row key, col01: ".$row->{key}.", ".$row->{col01}."\n";
I don't know if it will help you, I will explain how I did it.
Download and install Thrift compiler on your machine.
Install Thrift library for Perl client application using cpan
cpan Thrift
Move to the directory you installed Cassandra, there is interface directory inside it
cd /path/to/cassandra/interface/
Then generate Cassandra library for Perl using Thrift compiled you installed earlier
/path/to/thrift/binary/Thrift --gen Perl cassandra.thrift
It will create a directory gen-perl in the present directory, you will need to include it using use statement in your Perl scripts. Here's an example script, althou it doesn't work with newest versions of Cassandra and Thrift it is pretty similar, in case if you have issues I provide you with example that work with Cassandra-2.0.8 and Thrift-0.9.1.
#!/usr/bin/perl -w
use strict;
use warnings;
# Change for your environment
use lib '/path/to/cassandra/interface/gen-perl';
use Cassandra::Cassandra;
use Cassandra::Constants;
use Cassandra::Types;
use Thrift;
use Thrift::BinaryProtocol;
use Thrift::Socket;
use Thrift::FramedTransport;
use Data::Dumper;
# localhost and 9160 are default in storage conf for rpc listener
my $socket = new Thrift::Socket('localhost', 9160);
my $transport = new Thrift::FramedTransport($socket);
my $protocol = new Thrift::BinaryProtocol($transport);
my $client = new Cassandra::CassandraClient($protocol);
eval {
$transport->open();
my $consistency_level = Cassandra::ConsistencyLevel::ONE;
my $keyspace = 'DEMO';
my $column_parent = new Cassandra::ColumnParent();
$column_parent->{column_family} = "User";
$column_parent->{super_column} = undef;
$column_parent->{column} = 'age';
$client->set_keyspace($keyspace);
my $column = new Cassandra::Column();
my $row_key = 'Spider-Man';
$column->{name} = 'first';
$column->{value} = 'Peter';
$column->{timestamp} = time;
$client->insert($row_key, $column_parent, $column, $consistency_level);
$column->{name} = 'last';
$column->{value} = 'Parker';
$column->{timestamp} = time;
$client->insert($row_key, $column_parent, $column, $consistency_level);
$column->{name} = 'age';
$column->{value} = '18';
$column->{timestamp} = time;
$client->insert($row_key, $column_parent, $column, $consistency_level);
$transport->close();
}; if($#){
warn(Dumper($#));
}
1;
It adds an entry to Cassandra keyspace DEMO with key spider-man and following column values peter, parker, 18.
Here is the result of query on cassandra-cli after execution of this script:
[default#DEMO] list User;
Using default limit of 100
Using default cell limit of 100
(...)
-------------------
RowKey: spidey
=> (name=age, value=18, timestamp=1404222046)
=> (name=first, value=Peter, timestamp=1404222046)
=> (name=last, value=Parker, timestamp=1404222046)
(...)
4 Rows Returned.
Elapsed time: 367 msec(s).
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.
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