This question already has answers here:
What's the easiest way to install a missing Perl module?
(24 answers)
Closed 5 years ago.
can someone help me to exclude below the error.
Thanks in advance
Can't locate XML/Writer.pm in #INC (#INC contains: /home/svceln/usr/lib/perl5/site_perl/5.16.2/x86_64-linux /home/svceln/usr/lib/perl5/site_perl/5.16.2 /home/svceln/usr/lib/perl5/5.16.2/x86_64-linux /home/svceln/usr/lib/perl5/5.16.2 .) at /opt/apps/tomcat_scripts/allocate_ports.pl line 7.
BEGIN failed--compilation aborted at /opt/apps/tomcat_scripts/allocate_ports.pl line 7.
Error in allocating ports, server.xml cannot run`
The script i am using
#!/home/svceln/usr/bin/perl -w
# allocate_ports.pl
# allocate ports, create port_config.xml and write to stdout
use strict;
use XML::Writer;
use IO::File;enter code here
use File::Basename;
my ($increment) = 0;
my ($execDir) = dirname($0);
$#ARGV eq 0 or die "Usage: allocate_ports.pl server_name\n";
my ($port_read) = new IO::File ("$execDir/port_increment.txt");
if (defined $port_read) {
while (<$port_read>) {
chomp;
$increment = $_;
}
$port_read->close() or die "Can't close port_increment.txt: $!";
} else {
$increment = 0;
}
It might be in a package, say libxml-writer-perl, assuming Debian.
apt-cache search XML::Writer gives a list of packages if your system uses apt.
Depends on how you are getting your perl modules.
Related
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 am trying to use Perl on windows. I am think I am having a problem either with syntax or with access to CPAN information. What information I can find gives snippets on how to use the functions and when I try to use the examples I get errors.
I do not know how to get to CPAN. I tried to install it and it failed twice on GCC and dmake. I do not know if that would help or not. I used http://www.cpan.org/modules/INSTALL.html cpan App::cpanminus
I have a filename with the path ex:
c:\users\me\directory\\*.* This file contains a list of path+filename records for which I need the time and size of the file. When I read a record I can verify that the path+filename is correct.
I have had some help doing this in a batch file. I was using %~t1 and %~z1 as shown here:
pass the full path to the batch file then use
if "%~t1" == "" (
echo " AN ERROR OCURRED FOR THIS FILE/n"
) else (
echo fpath =%~1
echo time = %~t1
echo size = %~z1
)
When I tried to bring this over to Perl I can not get it to work. I have run out of hints and ideas to try.
I have tried to use a similar IF ( "%~t1" == "" ) {} but I get (missing operator before t1?).
I tried to use my $str1 = %~t1 and got "str1" not allowed while "strict subs" in use.
I tried to use $info->$ctime and got requires explicit package name.
I tried my $modtime = (stat($dirHandle))[9] with print "mod time = $mod_time \n"; and got no such class mod_time and syntax error.
I tried using the following I got from a perl programing documentation file for perl 5.20.1
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
I could not see how that would work and it did not. I got a lot of requires explicit package name
I tried this from the same reference
use File::stat;
$sb = stat($filename);
printf "File is %s, size is %s, perm %04o, mtime %s\n",
$filename, $sb->size, $sb->mode & 07777,
scalar localtime $sb->mtime;
I can not remember all the errors
Every time I see File::stat or Path::Class::File I do not know how to get any of these.
The perl monks are a little over my head as far as getting answers. I get lost in all the what ifs.
Thanks for any help you can give me.
Sounds like you're asking how to get the size and the last-modified time of a file.
Using stat:
use POSIX qw( strftime );
my $qfn = 'c:\\users\\me\\directory\\file';
my ($size, $mtime) = (stat($qfn))[7, 9]
or die("Can't stat \"$qfn\": $!\n");
printf("File %s: size=%s modified=%s\n",
$qfn,
$size,
strftime("%Y-%m-%d %H:%M:%S", localtime($mtime)),
);
Using File::stat, which replaces stat with a function with a friendlier interface:
use File::stat qw( stat );
use POSIX qw( strftime );
my $qfn = 'c:\\users\\me\\directory\\file';
my $stat = stat($qfn)
or die("Can't stat \"$qfn\": $!\n");
printf("File %s: size=%s modified=%s\n",
$qfn,
$stat->size,
strftime("%Y-%m-%d %H:%M:%S", localtime($stat->mtime)),
);
Both modules mentioned come with Perl. No need to install them.
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
I am trying to create a .exe in perl. It works fine until I try to compile it into an exe. I am using Komodo IDE 5. I have posted my script and the error below. I have added the modules, LWP::UserAgent, NET, and Google::Voice and it still doesnt work. I use perlapp to create the .exe
#!/usr/bin/perl -w
use strict;
use warnings;
use Google::Voice;
use Date::Calc qw(Delta_Days);
use Net::Twitter;
#Set Days
my #today = (localtime)[5,4,3];
$today[0] += 1900;
$today[1]++;
my #RT = (2012, 7, 7);
my $days = Delta_Days(#today, #RT);
#Get Quotes and Phone Numbers
open FILE, "c:/Countdown/countdownNumbers.txt" or die "Couldn't open file: $!";
my $numbers = join("", <FILE>);
close FILE;
open FILETWO, "c:/Countdown/Quotes.txt" or die "Couldn't open file: $!";
my $quotes = join("", <FILETWO>);
close FILETWO;
#Create Arrays and Lengths
my #numbersArray = split(/[\n\r\l]+/, $numbers);
my #quotesArray = split(/[\n\r\l]+/, $quotes);
my $length = #numbersArray;
my $QuotesLength = #quotesArray;
#Send Text Message
for(my $i = 0; $i < $length; $i++){
my $g = Google::Voice->new->login('secret', 'secret');
$g->send_sms($numbersArray[$i] => " Countdown\nDays Left: " . $days . "\n Quote:\n" . $quotesArray[0]);
}
#Send Twitter Message
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => 'secret',
consumer_secret => 'secret',
access_token => 'secret',
access_token_secret => 'secret'
);
my $result = $nt->update($days .' Days left!');
$result = $nt->update('Quote: ' . $quotesArray[0]);
#Rewrite the file and close it
open FILETWO, ">c:/Countdown/Quotes.txt";
for(my $i = 1; $i < $QuotesLength; $i++){
print FILETWO $quotesArray[$i] . "\n";
}
close FILETWO;
errors
Algorithm\Diff\XS.pm:
error: Can't locate Algorithm\Diff\XS.pm
refby: C:\Perl\site\lib\Array\Diff.pm line 7
Date\Calc\XS.pm:
error: Can't locate Date\Calc\XS.pm
refby: C:\Perl\lib\Date\Calc.pm line 26
I18N\Langinfo.pm:
error: Can't locate I18N\Langinfo.pm
refby: C:\Perl\lib\Encode\Locale.pm line 51
JSON\PP58.pm:
error: Can't locate JSON\PP58.pm
refby: C:\Perl\lib\JSON\PP.pm
Net.pm:
error: Can't locate Net.pm
refby: perlapp --add Net::
Can't locate Mojo/EventEmitter.pm in #INC (#INC contains:) at /<C:\Users\Chris\Desktop\Countdown\RT.exe>Mojo/Base.pm line 32.
BEGIN failed--compilation aborted at /<C:\Users\Chris\Desktop\Countdown\RT.exe>Mojo/UserAgent.pm line 2.
BEGIN failed--compilation aborted at /<C:\Users\Chris\Desktop\RTCountdown\RT.exe>Google/Voice.pm line 6.
BEGIN failed--compilation aborted at RT.pl line 4.
Compiling perl script into exe file is not so straight-forward, I'm afraid. ) Check this discussion at Perlmonks for details.
From what you've quoted it seems that you might start fixing that with installing additional modules: Algorithm::Diff::XS, Date::Calc::XS, etc.
If you use latest version of perlapp, send this error to ActiveState support.
Temporarily you can use PAR::Packer instead of perlapp. Install PAR::Packer with cpan shell (ppm may not work). Then run
pp -c t1.pl
It will create a.out. If it would not work, install Module::ScanDeps from svn: http://svn.openfoundry.org/par/Module-ScanDeps/trunk/ - I fixed a couple of possible problems for your program.
I never used perlapp, but it may have command line switches to provide a list of modules to include.
I have downloaded Langinfo.pm from http://search.cpan.org/src/RJBS/perl-5.16.1/ext/I18N-Langinfo/Langinfo.pm to C:\Perl\lib\I18N and it works.
Komodo IDE, version 6.1.3
Perl Dev Kit Pro v9.1.1.
ActivePerl-5.14.2.1402-MSWin32-x86-295342
Some time ago, I ask a question: How do I redefine built in Perl functions?
And the answers have served me well. I have a package that overrides Perl's 'open' function enabling me to log file access.
Now I've come to a case that breaks the functionality of the original code.
use strict;
use warnings;
use Data::Dumper;
sub myopen (*;#) {
my $p;
my $retval = CORE::open($p, $_[1]);
{
no strict;
*{"main::$_[0]"} = $p;
}
return $retval;
}
BEGIN {
*CORE::GLOBAL::open = *myopen;
};
my #a = (1, 2, 3);
open(CHECK, ">dump") or print "UNABLE TO OPEN DUMPER FILE: $!\n";
print CHECK "test\n";
print CHECK Data::Dumper->Dump(\#a);
close CHECK
Now I get this message:
Can't locate object method "CHECK" via package "Data::Dumper"
How do I fix it?
Try using a name other than "CHECK".
"CHECK" is a special function which is called during compile time, and you really shouldn't use it.
$ open CHECK , '<', 'foo.txt';
Took 0.00224494934082031 seconds.
Runtime error: Undefined subroutine &Devel::REPL::Plugin::Packages::DefaultScratchpad::CHECK called at (eval 329) line 5.
$ open CHECKS , '<', 'foo.txt';
Took 0.00155806541442871 seconds.
$
More on 'CHECK'
Why that specific error?
perl -MO=Deparse -e 'print CHECK Data::Dumper 1';
print 'Data::Dumper'->CHECK(1);
Also, you're using global file handles, which are problematic.
use this notation:
open my $fh, '<' , $foo ;
print <$fh>;
close $fh;
These are extra beneficial is they self-close when they go out of scope.
Compare:
> perl -MData::Dumper -e'local*_=*STDOUT;print _ Data::Dumper->Dump([2]);'
Can't locate object method "_" via package "Data::Dumper" at -e line 1.
to
> perl -MData::Dumper -e'local*_=*STDOUT;print _ ( Data::Dumper->Dump([2]) );'
$VAR1 = 2;
I used a different name from "STDOUT" because it seems to only gets the indirect object wrong when it's not a built-in handle.
This will work and without producing the error...
print {*CHECK} Data::Dumper->Dump(\#a);
This stops it being confused has an "Indirect Object Syntax"
However I do recommend steering clear of using CHECK and other special named code blocks in Perl and using lexical variables for filehandles is the preferred method. PBP