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
Related
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.
I get the following error:
Use of uninitialized value $_ in concatenation (.) or string at checkfornewfiles.pl line 34.
when attempting to run the following code :
#!/usr/bin/perl -w
#Author: mimo
#Date 3/2015
#Purpose: monitor directory for new files...
AscertainStatus();
######### start of subroutine ########
sub AscertainStatus {
my $DIR= "test2";
####### open handler #############
opendir (HAN1, "$DIR") || die "Problem: $!";
########## assign theoutput of HAN1 to array1 ##########
my #array1= readdir(HAN1);
######## adding some logic #########
if ("$#array1" > 1) { #### if files exists (more than 1) in the directory #######
for (my $i=0; $i<2; $i++) {shift #array1;} ####### for i in position 0 (which is the . position) loop twice and add one (the position ..) get rid of them #######
MailNewFiles(#array1);
} else { print "No New Files\n";}
}
sub MailNewFiles {
$mail= "sendmail";
open ($mail, "| /usr/lib/sendmail -oi -t" ) ||die "errors with sendmail $!"; # open handler and pipe it to sendmail
print $mail <<"EOF"; #print till the end of fiEOF
From: "user";
To: "root";
Subject: "New Files Found";
foreach (#_) {print $mail "new file found:\n $_\n";}
EOF
close($mail);
}
#End
I am new to perl and I don't know what's going wrong. Can anyone help me ?
A few suggestions:
Perl isn't C. Your main program loop shouldn't be a declared subroutine which you then execute. Eliminate the AscertainStatus subroutine.
Always, always use strict; and use warnings;.
Indent correctly. It makes it much easier for people to read your code and help analyze what you did wrong.
Use a more modern Perl coding style. Perl is an old language, and over the years new coding style and techniques have been developed to help you eliminate basic errors and help others read your code.
Don't use system commands when there are Perl modules that can do this for you in a more standard way, and probably do better error checking. Perl comes with the Net::SMTP that handles mail communication for you. Use that.
The error Use of uninitialized value $_ in concatenation (.) or string is exactly what it says. You are attempting to use a value of a variable that hasn't been set. In this case, the variable is the #_ variable in your foreach statement. Your foreach isn't a true foreach, but part of your print statement since your EOF is after your for statement. This looks like an error.
Also, what is the value of #_? This variable contains a list of values that have been passed to your subroutine. If none are passed, it will be undefined. Even if #_ is undefined, foreach (undef) will simply skip the loop. However, since foreach (#_) { is a string to print, your Perl program will crash without #_ being defined.
If you remove the -w from #!/usr/bin/perl, your program will actually "work" (Note the quotes), and you'll see that your foreach will literally print.
I do not recommend you not to use warnings which is what -w does. In fact, I recommend you use warnings; rather than -w. However, in this case, it might help you see your error.
You have EOF after the line with foreach. It contains $_ which is interpolated here but $_ is not initialized yet because it is not in foreach loop. It is not code but just text. Move EOF before foreach.
But probably you would like
sub MailNewFiles {
$mail= "sendmail";
open ($mail, "| /usr/lib/sendmail -oi -t" ) ||die "errors with sendmail $!"; # open handler and pipe it to sendmail
local $"="\n"; # " make syntax highlight happy
print $mail <<"EOF"; #print till the end of fiEOF
From: "user";
To: "root";
Subject: "New Files Found";
New files found:
#_
EOF
close($mail);
}
See perlvar for more informations about $".
The message
Use of uninitialized value $xxx in ...
is very straightforward. When you encounter it, it means that you are using a variable ($xxx) in any way, but that the variable has not ever been initialized.
Sometimes, adding an initialization command at the start of you code is enough :
my $str = '';
my $num = 0;
Sometimes, your algorithm is wrong, or you just mistyped your variable, like in :
my $foo = 'foo';
my $bar = $ffo . 'bar'; # << There is a warning on this line
# << because you made a mistake on $foo ($ffo)
I am trying to run a perl script 'googly.pl' from the command line, and it is giving some errors. Here is the script and the errors. I have re-checked the script, but I am still unable to successfully run the script.
#!C:\Strawberry\perl\bin\perl.exe
# googly.pl
# A typical Google Web API Perl script
# Usage: perl googly.pl <query>
# Your Google API developer's key
my $google_key='';
# Location of the GoogleSearch WSDL file
my $google_wdsl = "C:/vhosts/phpcs5/GoogleSearch.wsdl";
use strict;
# Use the SOAP::Lite Perl module
use SOAP::Lite;
# Take the query from the command-line
my $query = shift #ARGV or die "Usage: perl googly.pl
<query>\n";
# Create a new SOAP::Lite instance, feeding it
GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");
# Query Google
my $results = $google_search ->
doGoogleSearch(
$google_key, $query, 0, 10, "false", "", "false",
"", "latin1", "latin1"
);
# No results?
#{$results->{resultElements}} or exit;
# Loop through the results
foreach my $result (#{$results->{resultElements}}) {
# Print out the main bits of each result
print
join "\n",
$result->{title} || "no title",
$result->{URL},
$result->{snippet} || 'no snippet',
"\n";
}
Errors
Semicolon seems to be missing at C:/vhosts/phpcs5/googly.pl line 19.
Syntax error at C:/vhosts/phpcs5/googly.pl line 17, near "wsdl my "
Global symbol "$google_search" requires explicit package name at C:/vhosts/phpcs5/googly.pl line 17
Global symbol "$google_search" requires explicit package name at C:/vhosts/phpcs5/googly.pl line 19
Syntax error at C:/vhosts/phpcs5/googly.pl line 20, near "doGoogleSearch"
Execution of C:/vhosts/phpcs5/googly.pl aborted due to compilation errors.
my $query = shift #ARGV or die "Usage: perl googly.pl
<query>\n";
# Create a new SOAP::Lite instance, feeding it
GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");
should be
my $query = shift #ARGV or die "Usage: perl googly.pl <query>\n";
# Create a new SOAP::Lite instance, feeding it GoogleSearch.wsdl
my $google_search = SOAP::Lite->service("file:$google_wdsl");
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 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