If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this section is the place to ask.
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
The command fails to load the module, hanging until I kill it. Here's the output:
Reading '/Users/me/.cpan/Metadata'
Database was generated on Wed, 26 Oct 2016 18:53:30 GMT
Reading '/Users/me/.cpan/sources/authors/01mailrc.txt.gz'
......................................................................
+......DONE
Fetching with LWP:
http://mirror.jre655.com/CPAN/modules/02packages.details.txt.gz
LWP failed with code[500] message[Can't connect to mirror.jre655.com:8
+0 (nodename nor servname provided, or not known)]
Trying with
/usr/bin/curl -L -f -s -S --netrc-optional
to get
http://mirror.jre655.com/CPAN/modules/02packages.details.txt.gz
curl: (6) Could not resolve host: mirror.jre655.com
Function system("/usr/bin/curl -L -f -s -S --netrc-optional "http:
+//mirror.jre655.com/CPAN/modules/02packages.details.txt.gz" > "/User
+s/me/.cpan/sources/modules/02packages.details.txt.gz.tmp13888"")
returned status 6 (wstat 1536), left
/Users/me/.cpan/sources/modules/02packages.details.txt.gz.tmp13888 wit
+h size 0
Warning: no success downloading '/Users/me/.cpan/sources/modules/0
+2packages.details.txt.gz.tmp13888'. Giving up on it.
Fetching with LWP:
http://mirrors.sohu.com/CPAN/modules/02packages.details.txt.gz
I have a server which is local (192.168.0.10) and I know mailx works correctly, because I can send an email directly from the terminal, even if I am local. This is the beauty of SimpleSMTP.
I have a program that sends an email with ssmtp (SimpleSMTP) via mailx. If the email is sent and there is no error, the user gets the sms and the web user gets back to the main menu page.
If there is an error (Telus blocks me after a few tries), I tried to catch it with the END statement to send it back to the main menu, but it doesn't work.
Here is the code, with dummy email and domain:
It's part of a sub:
In the web site logs, I get "mailx: ... message not sent:".
Thanks in advance.
$courrielclient="5555555555\msg.telus.com";
$textecourriel = "Ceci est un test de message texte (SMS)";
$sujet = "Test de rappel de rendez-vous $nomfournisseurcellulaire";
$from = "nepasrepondre\@testsms.ca";
open( my $mail, "| mailx -r $from -s $sujet $courrielclient");
say ("$mail $textecourriel");
close $mail;
END {
my $redirect = "/cgi-bin/chiro/menuprincipal.pl";
print "Location:$redirect\n\n";
}
My apologies if this seems to be old hat but frustration has now become annoying and an internet search has not come up with an appropriate solution:
I wrote a perl program 2 years ago that worked and did what it was told to/asked to do and it utilised:
use Tk
I am now trying to rerun this program but it fails at trying to 'find' Tk - sure enough the module is not in any of the libraries in the path. Why it is no longer there is for another frustrating investigation by Yours Truly
I have tried re-installing it using ppm, cpan, cpanm (with and without 'forcing') but there is always something that fails
It also seems that Tk is no longer the simple name for this module but it has a version number as part of the build
All I want is my simple TK module back so that my loyal program can fulfil its duties once more.
I am using Strawberry Perl, v5.38.0 on a 64 Windows 10 machine
Greetings.
I have a question about prepare-execute statements when passing a list of integers.
I'd like to figure out how to get the first query below ( SELECT recno, body FROM body WHERE recno IN (?); ) to produce the same three db records that the second query produces. Currently Dumper() shows an empty set for the first query but shows the correct three records for the second query. So the first query produces and empty set. The second query produces three records as expected. The difference seems to be a matter of query syntax. I am stumped as to the correct syntax for the prepare statement.
#!/usr/bin/perl
use DBI;
use Data::Dumper;
use strict;
use warnings;
my %bodies = ();
my $sth;
my @recnos = (2284, 2285, 2286);
my $dbfile="database-example.sqlite3";
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", undef, undef,
{ AutoCommit => 0, RaiseError => 1 })
or die("Could not open database '$dbfile': $!\n");
# this produces an empty set
my $query = 'SELECT recno, body FROM body WHERE recno IN (?);';
$sth = $dbh->prepare($query)
or die("prepare statement failed: $dbh->errstr()\n");
$sth->execute( join(',', @recnos) )
or die("execute statement failed: $dbh->errstr()\n");
my $bodies = $sth->fetchall_arrayref;
print "Part A\n",Dumper($bodies);
print "-"x39,"\n";
# this produces the expected three records
my $query = 'SELECT recno, body FROM body WHERE recno IN (2284, 2285,
+2286);';
$sth = $dbh->prepare($query)
or die("prepare statement failed: $dbh->errstr()\n");
$sth->execute( )
or die("execute statement failed: $dbh->errstr()\n");
my $bodies = $sth->fetchall_arrayref;
print "Part B\n",Dumper($bodies);
$sth->finish;
$dbh->disconnect;
exit(0);
A work-around would be to just create a large query string and not worry about the place holder, but somehow I have it in my mind that place holders are the way to go. Sorry, I can't package this one up as a standalone, ready-to-run script as far as I know.
Hello dear Perl Monks
My brain is on strike and I cannot find out the regex with the following properties:
- the occurence of the string is optional (0 or one occurences)
- if there the string is present, it has to start with '#'
- this string should be captured, without this leading mandatory character '#'
Good day monks. I have an application that is threaded with Parallel::Forkmanager. I am trying to use a counter to keep track of progress like so (partial code):
our $ctr = 0;
say "processing duplicates...";
LOOP:
foreach my $pid (@duplicated) {
$pm->start and next LOOP; # do the fork
unless ($ctr % 1000) {say $ctr;}
$ctr++;
#do stuff
$pm->finish; # exit the child process
}
In Perl I have a script 'a.pl' that calls a module 'MyModule.pm' and inside that module
there's a call with function 'call()' to another module 'MyModule2.pm' function '$authorize'
as 'MyModule2::authorize()' but MyModule2 is not loaded with 'use MyModule2' inside MyModule.pm.
But I get no error "module cannot be found" when running the script 'perl a.pl' which calls 'MyModule.pm' function 'call()' which calls 'MyModule2::authorize()'
Only if I run 'perl MyModule.pm' I get error "MyModule2.pm not found".
Very simply I don't have a 'use Data::Dumper' line in my script
but when later on doing 'print Dump $myvar' I get no error!
Also when doing 'print Dumperrrrrrrrrr $myvar' I get no error too!
Why is that???????
I have some common modules that are used in several places so I have created a directory for them at /usr/lib/perl_modules. I want to include this location in @INC for every user, including CRON.
I've added export PERL5LIB=/usr/lib/perl_modules in both /etc/environment and /etc/profile.
When I list the environment variables, PERL5LIB is there as expected. But when I try to use on of the modules I get an error:
Can't locate my_module.pm in @INC (you may need to install the my_modu
+le module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/
+perl/5.36.0 /usr/local/share/perl/5.36.0)
There are other locations in @INC but /usr/lib/perl_modules is not one of them...
I suspect the environment variable is set for root that I'm using to list the variables, but not for whatever process is running the script within Apache.
How can I properly set PERL5LIB for all users and processes or is there a better way to get an extra entry in @INC for every script without having to use lib in every script?
I'm working on binding some JS and Perl code using Bun FFI (https://bun.sh/docs/api/ffi) and perlembed. Things work good, except for XS dynamic loading. Probably due to the way the Bun FFI links to the boot_DynaLoader in my libperl.so, and the general lack of tools and knowledge on my part to circumvent, emulate or recode some of those parts.
So, my question: where or how in core is the libperl boot_DynaLoader C function defined? I just can't find it! I've been to the Perl core code and docs on XS, boot_DynaLoader and ExtUtils::Embed, but to my surprise I can't figure how it works or where its code resides in core (my core is 5.22.1).
Any leads, links or pointers to help me acquire the knowledge of the inner workings of dynamic loading would be of great help.
PD: I didn't want to bore you with my code, but here it is, for context:
The above does not dynamic loads XS modules as intended due to the way the FFI library exports symbols, which are meant primarily to be used within the JS realm, not to be sent back to libperl as a callback or (void *)() pointers. I've tried some other workarounds and practices, ie using my own compiled xs_init() function from C and FFI linking to that, but loading is still not working. I probably will be able to solve it at some point, but still, I'd like to understand the inner workings of the core in that regard. I got it working on darwin x86 by accident, but the same workaround fails in linux.
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).