Endorsement from committer to submit TPF Grant Application to add given/when to Switch.pm
4 direct replies — Read more / Contribute
|
by ait
on Apr 01, 2024 at 09:47
|
|
Hi there, fellow monks!
If a committer is reading this, I would like to submit a grant not for myself for for Switch.pm author or any other volunteer to add given/when to Switch.pm
It's ironic that such a widely used module (Switch.pm) actually recommended for people to migrate to given/when and now Perl core decided to deprecate starting in 5.38
Adding a simplified, mostly compatible given/when in Switch.pm would save a lot of people a lot of trouble. I can suspect that most people just used it as a fancy if/elsif/else and did not use a lot of the smart matching capabilities, although I could be wrong. In any case, I think that in TIMTOWTDI tradition, we should add given/when to Switch.pm and allow most people to simply replace use feature 'switch' by use Switch
I am confident a committer will pick up this thread and endorse this proposal in my TPF Grant application, so I will just link this tread ;-)
TIA
Alex
|
Trouble with MCPAN
2 direct replies — Read more / Contribute
|
by mron
on Apr 01, 2024 at 02:12
|
|
I tried to execute this command on a MacBook running osX 14.4.1:
perl -MCPAN -e 'install XML::Parser'
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'd like to know why it fails and how to fix it. Failing that, I'd like to know another way to load the module,
Thanks
|
catch die from say
3 direct replies — Read more / Contribute
|
by PierreForget
on Mar 31, 2024 at 17:25
|
|
Hi Monks,
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";
}
|
Tk in Strawberry on W10
3 direct replies — Read more / Contribute
|
by gsd4me
on Mar 30, 2024 at 18:55
|
|
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
Any guidance would be most gratefully received
ADB
|
DBI qw(:sql_types) with placeholders versus SQLite3
1 direct reply — Read more / Contribute
|
by mldvx4
on Mar 30, 2024 at 14:45
|
|
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.
|
Simple Regex drives me insane
5 direct replies — Read more / Contribute
|
by cheerydog
on Mar 30, 2024 at 10:30
|
|
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 '#'
Example:
'bli bla' -> $1 is empty
'#foo bli bla'. -> $1 is 'foo'
Thanks anyways and highest regards
Cheery
|
Why is my counter not updating in a threaded application?
2 direct replies — Read more / Contribute
|
by cormanaz
on Mar 29, 2024 at 14:35
|
|
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
}
The counter is printing, but it's always zero. Why isn't it incrementing properly?
|
Perl doesn't give error when module is not found 2
5 direct replies — Read more / Contribute
|
by Anonymous Monk
on Mar 26, 2024 at 06:53
|
|
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".
|
Perl doesn't give error when module is not found
3 direct replies — Read more / Contribute
|
by Anonymous Monk
on Mar 26, 2024 at 06:36
|
|
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???????
|
PERL5LIB not in @INC
3 direct replies — Read more / Contribute
|
by Bod
on Mar 23, 2024 at 10:56
|
|
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?
|