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.
I use smartmatch for checking whether an integer number is within a certain range, like this:
if ( $number~~[1416..1494] ) { do whatever }
But since i upgraded to a recent Perl version i'm getting a "Smartmatch is deprecated" warning.
Why would such a useful operator be depreciated?
Do I really have to replace '~~' with:
if ( $number>=1416 and $number<=1494 ) { do whatever }
Is there a more elegant solution similar to the smartmatch example?
Also is this depreciation of smartmatch definitive or is there a chance that the Perl devs will change their mind and keep it?
Perl is great because of these brilliant operators, removing them removes a bit of the uniqueness of Perl.
Is it any longer possible to download full perl documentation,
that I can read while I'm off-line?
I can now read on-line e.g. https://perldoc.perl.org/perlvar .
I'm glad that the information is still available.
I used to be able to see essentially this page by typing,
at the bash prompt, something like 'man perlvar'. I'd like to
be able to do this now, when I'm off-line, NOT by pulling
up a page from the internet, such as the above example.
Is this any longer possible?
Trying to figure out how to do this, I see messages such
as "You need to install the perl-doc package to use this program."
These fail to find or to install anything useful:
apt install perl-doc
apt install perldoc
apt search perldoc
apt search perl-doc
aptitude install perl-doc
aptitude install perldoc
aptitude search perldoc
aptitude search perl-doc
cpan -i perl-doc
cpan -i perldoc
If it's any longer possible to download full perl documentation
onto my computer's hard drive, I'd like to know what it is.
My thanks in advance for any suggestions.
Very truly yours,
jf02ir@gmail.com
I have observed that the greek phrase
"Πληθαίνουν και βαραίνουν τα ερωτήματα"
translates differently depending on how the browser was launched:
via Mechanize and Chrome the translation is Are growing and heavy the questions -- which I consider dumb, compared to
The questions are multiplying and burdening yielded in the same way but when the browser (chrome or firefox) was launched "normally".
The second translation is produced with Firefox and Chrome, with or without uBlock. The reference to uBlock is because I thought that that was the decisive factor before I realised it was the way the browser is launched (Hence my delirious rumblings at the CB some minutes ago ...).
If some Monks want to experiment:
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($ERROR);
my $mech = WWW::Mechanize::Chrome->new(
headless => 0,
launch_arg => []
);
sleep(1000);
"They were a very vocal people. They enlivened their wanderings by feasts, at which there was much drunkenness and at which a special sort of man, the bards, would sing and recite."
The Greek translation with google-mech-perl yields: "Ήταν ένας πολύ φωνητικός λαός. Ζήτησαν την περιπλανώμενη τους από τις γιορτές, στις οποίες υπήρχε πολύ μεθυστικότητα και στην οποία θα τραγουδούσαν και θα απαγγέλλουν ένα ειδικό είδος ανθρώπου, οι bards." Exactly the same translation with firefox-mech-python. But properly-launched Firefox yields "Ήταν πολύ φωνητικός λαός. Ζωντανεύουν τις περιπλανήσεις τους με γλέντια, στα οποία υπήρχε πολύ μέθη και στα οποία ένα ιδιαίτερο είδος ανθρώπου, οι βάρδοι, τραγουδούσε και απήγγειλε." Which is much more correct. Firstly, the word "bards" translates correctly to "βάρδοι" (this is left un-translated in both mech cases). Also the tense of the last two verbs is wrong in the mech cases and additionally the two verbs are in slightly different tense (difference between will recite and would recite. Also, the proper Firefox translates these two verbs correctly in singular form because it detects that the singers was the "special sort of man" (singular) and not "bards" (plural). Anyway, I am not expert on grammar/syntax of any language but the mech translations "sound" weird to my ears. The bottom line is that both mech cases yield "weird-sounding" translations, haphazard I would say, whereas the properly-launched firefox (and chrome) yield a much better-sounding translation.
The same text to German:
"Sie waren ein sehr lautstarker Volk. Sie belebten ihre Wanderungen durch Feste, bei denen es viel Trunkenheit gab und zu denen eine besondere Art von Mann, die Barden, singen und rezitieren würde." from both mech. Proper Firefox yields: "Sie waren ein sehr lautstarkes Volk. Sie belebten ihre Wanderungen durch Feste, bei denen viel getrunken wurde und bei denen eine besondere Art von Menschen, die Barden, sang und rezitierte." Zero German understanding from me, so I can not comment.
I want to make a program which does the following :
- Input audio from sound card line-in
- Get it in raw format (FIFO of the data, xxxx Hz sampling rate x xxxx bit resolution)
- Do some processing which would be suitable to show a matching visualization (so need to be able to run DTFT to obtain the spectrum)
This should be able to run in near real time (no requiring of "proper" real time, just be able to run along with the arriving analog input, not buffering it all for revisit later
This should run on a modern Linux system, where the main sound platform is ALSA, and support for old Linux sound technologies (OSS, etc) might not be available or not work correctly etc
So what i am asking is, what libraries or example code would you recommend me to look into ? - I found several mentions of modules on cpan which use OSS, but i am not sure whether it is supported properly on modern linux, and whether there are any newer and better suited libraries which are not widely known
my $msg = "Hello 'name' welcome to earth";
my $query = $dbh->prepare("SELECT DISTINCT email FROM users");
$query->execute();
my $records = $query->fetchall_arrayref;
my @to;
for my $em ( @$records ) {
push @to, @$em;
}
for my $recipient(@to) {
mail($recipient);
}
sub mail {
my $recipient = shift;
my $smtpserver = 'smtp.dddd.com';
my $smtpport = 587;
my $smtpuser = '';
my $smtppassword = '';
my $transport = Email::Sender::Transport::SMTP->new({
host => $smtpserver,
ssl => 'starttls',
port => $smtpport,
sasl_username => $smtpuser,
sasl_password => $smtppassword,
});
my $email = Email::Simple->create(
header => [
To => $recipient,
From => 'dddd@ddd.com',
Subject => $sub,
'Content-Type' => 'text/html',
],
body => $msg,
);
sendmail($email, { transport => $transport });
my $Response = "Success!";
}
Hello esteemed monks, I am having trouble using wide characters in filenames on Windows 10 using File::Copy. The wide characters appear just fine if I write them to a text file, and I can manually copy/paste them into filenames in Windows Explorer, but if I use File::Copy they come out all wonky.
use File::Copy;
my $oldname = "file.txt";
my $newname = "Hildur_Guðnadóttir.txt";
copy(oldname, $newname);
I guess it's accepted and expected, but I can't find any documentation that explains this differing behaviour.
Without the enclosing parens, the exit function behaves as I expect - otherwise the specified value is apparently ignored, and the exit call defaults to exit 0.
And the result is the same as when I leave out the -checked part: the html does NOT say checked. I inspected the actual HTML and its inexplicably missing. I added a debug point to print the HTML right after the checkbox ; its decidedly not there. The most vexing part- earlier today it worked. I've run the usual gauntlet of trying "checked", 1, "on" etc , recommended by various Perl sites; none cooperate today.
So being the end of the day Friday, I hate to be defeated, but I just added:
Which is really undesirable, and FUGLY, since the preference is to let the Perl CGI do the work. But unlike the CGI, THIS WORKS!
I'll review this Monday for suggestions but note to whoever wrote the Perl CGI- checkbox is a HOT MESS! Everytime I write code that has to check a checkbox it's like i DREAD it! Pretty much everything else in the CGI works as stated, but since this setting is stated like 6 different ways, maybe its not amazing it seldom works.
This was so frustrating that Monday I plan to look at the actual checkbox code IN the Perl CGI, but I just know it'll be like a switch with 3 globs, 2 closures, and 3 evals!!
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).