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.
If you enable warnings, you see a line Variable "$v" is not available at (eval 3) line 1. Googling that led me to a stack overflow response which seems to relate to your case (2nd answer, starting with See perldiag)
timka7060's reaction:
So why does the first eval output 111?
(I'd figure either both lines should be 111 or both undef.)
Btw, prior to 5.10, both lines would output 111: https://perlbanjo.com/b28dce8db2
This is a simple fix, but only for a single variable:
https://perlbanjo.com/13dbb8d48d
I need to install a Mail Transfer Agent that will be used with MIME::Lite
I understand that the modern choices are Postfix or Exim. However, MIME::Lite says it uses sendmail which is pretty old isn't it?
I have never looked at MTA's before so any advice would be appreciated. This is being installed on a RaspberryPi. Does the MTA only deal with outgoing mail or will it manage incoming mail as well? If not, what do I need for that?
In the course of writing a bunch of perl code for my firm, I noticed that some subs were used over an over and some variables were most naturally implemented as global variables.
After some experimentation I hit upon a method of making this happen. Let "program.pl" be one of the perl programs which needs to use (a) one of these common subs and (b) needs to share some variables with this sub.
Context: This is in Windows 10 (ugh) using Strawberry perl v5.20.2.
I construct a file "includee.pm" which looks like this:
use vars qw
{
$SHAREDVARIABLE1
@SHAREDVARIABLE2
%SHAREDVARIABLE3
...
}
sub function
{
...
}
Both program.pl and includee.pm are in the same folder, which is also the current folder when the program runs.
This actually produces the desired effect: the shared variables are accessible in both progam.pl and includee.pm, and the sub function is callable from program.pl.
The question is: is this legitimate? Am I depending on a quirk, which might go away in a future version of perl? In particular, will this method work in a linux context also?
I am looking for the exact definition of DateCalc and Delta_Format functions in Date::Manip and I seem not to be able to find those definitions. Could somebody please point me to those definitions.
Thank you
ZA
use strict;
use warnings;
use Math::BigInt;
# The following line of code will die with:
# Can't locate object method "palt" via package "Math::BigInt" at try.
+pl line 7.
# palt Math::BigInt->new(123456);
# But this next rendition is fine, and works as expected:
palt(Math::BigInt->new(123456));
sub palt {
my $arg= shift;
print "$arg\n";
}
__END__
Outputs:
123456
I need to calculate CRC-16/X25 checksum/digest in order to communicate with some instrument. I am using Digest::CRC module and https://crccalc.com/ site for both the source of appropriate parameters and to check the result. (The examples in the instrument manual agree with results on csccalc.com.) However, I cannot seem to get correct results. Here is a snippet of may code:
I am either interpreting the parameters incorrectly, on missunderstand the arcana of pack/unpack functions and the need for them, or something else entirely.
A bit of enlightenment would be appreciated.
Blessed Monks, I humbly prithee guidance bestow.
I'm looking to benchmark for a variant of the binary search algorithm, but before I begin I'm trying to bake it down to the most efficient Perl code I possibly can. I'm looking for the most efficient way to find the Most Significant Set Bit of a given integer value. I am unaware of a Perl function that does this. I have almost no experience in C, but I read that GCC does have an algorithm for this. Up to now, I have been using the following code to find the most significant set bit of a given 64-bit integer. I did my best to format it legibly here; though it looks like puke, it's a single statement. Is there a better performing solution?
Hi Monks, how can I extract the email button the js button on this page:
https://reporter.nih.gov/project-details/10573139
Here's some code I've written that gives me a pdf but I need to have the script click the button before I grab the pdf and I can't figure that out. I tried to see if I could 'tab' to it as I could automate that with 13 tabs and a return or something but the button doesn't select. Any ideas/help are greatly appreciated.
use strict;
use File::Spec;
use File::Basename 'dirname';
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
my $url = 'https://reporter.nih.gov/project-details/11011199';
my $mech = WWW::Mechanize::Chrome->new(
headless => 1, # otherwise, PDF printing will not work
);
print "Loading $url";
$mech->get($url);
sleep 5;
my $fn= 'screen.pdf';
my $page_pdf = $mech->content_as_pdf(
filename => $fn,
);
print "\nSaved $url as $fn\n";
I am not very experienced with perl, but I know enough that this looks pretty bad
$dbh->begin_work;
my $href = $dbh->selectall_hashref("SELECT * FROM data WHERE ToScan IS
+ NULL AND title IS NOT NULL limit 1 FOR UPDATE SKIP LOCKED", "someid"
+);
foreach my $tmp (keys %$href) {
$ID=$href->{$tmp}->{'id'};
$title=$href->{$tmp}->{'title'};
$channel=$tmp;
}
my $rsth=$dbh->prepare("UPDATE data SET lock=1 WHERE id='$ID'"); $rsth
+->execute() || die $rsth->errstr;
$dbh->commit;
is there any cleaner way of doing this? I need to "...FOR UPDATE" then get the ID of selected row to set a lock on it. My code works but is very ugly. Thank you
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).