Outlier test fail
in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
|
by Bod
on Jan 11, 2024 at 16:34
|
|
I've been checking CPAN Tester results for one of my modules and noticed a single failure amidst a sea of passes. On checking it, is from Test::More is returning 0.99999999999999996 instead of 1.
My best guess is that the machine doing the testing has a peculiar build somewhere that is affecting the floating point arithmetic.
- Is that a fair assumption?
- Is there anything I can do about that?
- Is it worth doing anything about this?
|
Another Unicode/emoji question
in Seekers of Perl Wisdom
5 direct replies — Read more / Contribute
|
by Bod
on Dec 21, 2023 at 19:31
|
|
I realise that we've had a very long recent thread about Unicode...sorry if this drags the issue out further! However, I have little understanding of Unicode, and I rarely needed to know. But I could do with some help, please...
My partner runs a dog care business and I have built the booking platform for her. Part of this provides a URL to Google Calendar to update our mobile calendars from the booking system. This all works fine but I'll ask a couple of more general questions at the end.
I decided it would be nice to have a Dog Face Emoji as the first character of the title of the calendar entry. But I cannot get this to display. The script uses Template to generate the ICS feed for Google Calendar.
BEGIN:VCALENDAR
VERSION:2.0
PRODID:Pawsies Calendar 1.0//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
[% FOREACH event IN day %]BEGIN:VEVENT
SUMMARY:\x{e052} [% event.type %][% IF event.dog %] - [% event.dog %][
+% END %]
[% IF event.note %]DESCRIPTION: [% event.note %]
[% END %]UID:pawsies[% event.idBooking %][% event.id %]@pawsies.uk
SEQUENCE:[% event.sequence %]
DTSTAMP:[% event.dtstart %]
DTSTART:[% event.dtstart %]
DTEND:[% event.dtend %]
URL:https://www.pawsies.uk/admin/calendar/?day=[% event.date %]
COLOR:[% event.color %]
END:VEVENT
[% END %]END:VCALENDAR
Everything works as expected except the emoji is printed as a literal \x{e052} instead of a 🐶 - I have use utf8; at the top of the script and the HTTP Header is:
Content-type: text/calendar; charset=utf-8
A couple of extra questions if you are experienced at feeding data to Google Calendar:
1 - Is it possible to force Google to refresh the feed? Waiting for 24 hours or so makes debugging slow and tedious.
2 - Is it possible to set the colour of the event from the ICS feed so we can have multiple colours from one feed? Currently, we have two feeds just to get two different colours. I've tried the COLOR property but it seems to be ignored.
Updated to correct MIME type
|
CPAN Testers shows N/A
in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
|
by Bod
on Dec 19, 2023 at 18:24
|
|
I've released an updated version of AI::Embedding - version 1.1
The CPAN documentation shows the latest version. However, CPAN Testers is showing N/A for all Perl versions, not just the ones before the minimum Perl version. This seems very strange. Have you come across this before?
Also, when I try to upgrade to the latest version, it doesn't happen
C:\Users\bod>cpanm AI::Embedding
AI::Embedding is up to date. (1.01)
I've checked that I haven't inadvertently specified a minimum Perl version that doesn't yet exist.
Any suggestions for what to check that might be causing this?
|
Path to prove
in Seekers of Perl Wisdom
2 direct replies — Read more / Contribute
|
by Bod
on Dec 18, 2023 at 18:12
|
|
|
Anonymous subroutines
in Seekers of Perl Wisdom
7 direct replies — Read more / Contribute
|
by Bod
on Dec 10, 2023 at 18:00
|
|
Recently, I've noticed a few places where anonymous subroutines have been declared for no apparent reason:
my $function = sub {
# ...do stuff...
};
# Call the sub
$function->('param');
I would write the same subroutine as such:
sub function {
# ...do stuff...
}
# Call the sub
function('param);
The above two code snippets appear to do exactly the same thing. But is there a subtle difference lurking there that I have overlooked? Is there a reason to write the first form instead of the second?
I don't think I have ever written a stand-alone anonymous subroutine like this. The only place I generally use anonymous subs is as a 'value' in a hash. Typically, to pass to Template to keep logic separated from display like this:
my $vars = {
'date' => $date,
'format' => sub { return ucfirst lc $_[0]; },
};
$template->process('example.tt', $vars);
|
Character encoding in emails
in Seekers of Perl Wisdom
8 direct replies — Read more / Contribute
|
by Bod
on Dec 05, 2023 at 16:59
|
|
I have two email-sending processes. Both are seemingly the same but they produce different results. Both use MIME::Lite.
One sends emails immediately, the other is for larger numbers of emails and consists of an email queue held in a MariaDB database. The sending script runs every 20 minutes from CRON. The body text for both gets to them from an HTML textarea and they have been tested using identical body text.
If we add an emoji character to the body text, the queue sends it correctly. But the immediate sending script produces ��� instead of the emoji.
As far as I can tell the only differences between the scripts is that one runs under CRON and stores and retrieves the body using a database. Other than that they seem identical.
Both scripts use utf8;
I am at a loss how to debug the problem...what would you try to get to the root of this problem?
|
XS Modules - why and when?
in Seekers of Perl Wisdom
⭐
9 direct replies — Read more / Contribute
|
by Bod
on Dec 04, 2023 at 19:22
|
|
I know little about XS modules but I was looking at RPi::DHT11 and noticed that it is an XS module which seemed a little strange. Hence the question here. I was going to email stevieb, the author and ask but thought it would be good to get other people's take on this.
My understanding of an XS module is that it uses XSLoader to load C / C++ / C# code. The Perl is just a wrapper around the loaded code with the Perl doing little processing. I believe the main reason to do this is for speed as compiled languages of the C family are faster than interpreted languages such as Perl. Is that about right so far?
Assuming that is something like correct...
Why would the RPi::DHT11 module use XS? The DHT11 is a temperature and humidity sensor with a maximum frequency of 0.5Hz (one read per 2 seconds). So speed is not the issue here!
What reason would there be for creating an XS module in this use case? Would it not be easier and simpler and just as fast given the speed of the sensor, to write all the code in Perl?
I'm hoping for more insights into the world of XS modules here...
|
Capture Groups
in Seekers of Perl Wisdom
3 direct replies — Read more / Contribute
|
by Bod
on Nov 14, 2023 at 15:11
|
|
I've had cause to run some code from the console that usually only gets run on a webserver. In its usual environment, it doesn't give me warnings. But, from the console, I get a warning...
$result =~ s/(Mr(s)?) a/\1 A/s;
\1 better written as $1 at...
I have always been under the impression (or perhaps illusion) that \1 should be used within the regular expression and $1 outside of it. Like this:
if ($test =~ /some_test/) {
$foo = $1;
}
Has something changed in the preferred way to capture in a regular expression, or have I been doing it wrong all the time?
|
Wide characters and UTF8
in Seekers of Perl Wisdom
1 direct reply — Read more / Contribute
|
by Bod
on Nov 08, 2023 at 11:00
|
|
Could you please help me with this little script?
I am trying to pre-parse (i.e. check that I can get the data I need) a JSON file from the UK Charity Commision. The data source is not known for being well-formated but I am pretty sure the issue here is with my code and (lack of) understanding of character encoding!
use strict;
use warnings;
use Data::Dumper;
use utf8;
use JSON;
$/ = undef;
open my $fh, '<:encoding(UTF-8)', 'publicextract.charity.json' or die
+$!;
my $data = <$fh>;
close $fh;
$data =~ s/^\x{feff}//; # Strip off BOM
my $json = decode_json $data; # <-- Wide character in subroutine ent
+ry at json.pl line 15.
foreach my $j(@$json) {
print "$j->{'charity_contact_phone'},$j->{'charity_contact_email'}
+\n";
}
print "\nComplete!\n\n";
The documentation for decode_json says it takes a UTF8 encoded string. So I have saved the JSON file as UTF8 using TextPad and opened the file with the same encoding. But, decode_json is croaking Wide character in subroutine entry
What have I overlooked?
|
Displaying POD like MetaCPAN
in Seekers of Perl Wisdom
5 direct replies — Read more / Contribute
|
by Bod
on Nov 07, 2023 at 16:50
|
|
Do you know of any modules or services that can display POD in the same (or similar) style as MetaCPAN?
We want to document internal modules consistently and it seems sensible to keep the layout and style in one with public modules.
|