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 am doing some timezone conversions, and I am realizing that this has some cavetas I am not understanding. In this particular case I am trying to convert from CET to Greenwitch. This is one hour difference, yet this script gives me two. It has probably to do with summer/wintertime? Which is the best approach to have precise conversions?
use DateTime;
use DateTime::Format::Strptime;
my $db_update_time = '2024-04-07 15:03:27';
my $parser = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%d %T',
locale => 'en_US',
time_zone => 'Europe/Berlin',
on_error => 'croak',
);
my $datetime = $parser->parse_datetime($db_update_time);
$datetime->set_time_zone('Greenwich');
$formatted_time = $datetime->strftime('%Y-%m-%d %T');
print $formatted_time;
#output: 2024-04-07 13:03:27
We've started the process of moving hosting server to a cheap VPS - just non-essential (read "hobby") sites for now whilst we get to grips with it and I learn how to manage a server...
All is going relatively well so far, but I've found an anomaly with time settings. Can anyone explain what is going on?
The 'old' server observes DST whereas the 'new' server doesn't. If I run timedatectl on the 'new' server it tells me it is set to UTC. I don't have access to run the same command on the 'old' server.
Here in the UK we are now on BST (GMT+1) so things that are time dependent (like Google Calendar feeds) that have been moved over are all 1 hour out. If I get the time from the MariaDB database SELECT NOW() I get GMT, as expected.
However, I have a bit of test code left in a page that only I use. It's a bit of JavaScript document.write(document.lastModified); which shows the time in BST. Doen't that time get passed in the HTTP headers from the Perl generated web page? Perl is, of course, also reporting GMT.
The obvious solution seems to be to change the server time from UTC to GMT.
Will that then observe UK DST?
Are there any reasons not to change the server to GMT bearing in mind that the entire codebase was written on a server that observes DST?
Update: - the "obvious" option to set would be 'Europe/London' but that is not included in timedatectl list-timezones
I have code where a forked process is generating a list in $data and passing that to the callback like in this simplified version:
use strict;
use feature ':5.10';
use Parallel::ForkManager;
our $pm = Parallel::ForkManager->new(8);
$pm -> run_on_finish ( # called BEFORE the first call to start()
sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_
+structure_reference) = @_;
# retrieve data structure from child
if (defined($data_structure_reference)) { # children are not
+forced to send anything
my $string = ${$data_structure_reference}; # child passe
+d a string reference
if ($string) {
#how to process $string?
};
}
else { # problems occurring during storage or retrieval will
+throw a warning
say qq|No message received from child process $pid!|;
}
}
);
LOOP:
foreach my $instance (0..100) {
$pm->start and next LOOP; # do the fork
my $data;
foreach my $i (0..50) {
push(@$data,int(rand(10));
}
$pm->finish(0,\$data); # exit the child process
}
$pm->wait_all_children;
The docs say you can use this method to return a data structure, but they refer to the thing returned as a string. Is $string really a string or is it an object?
I was looking at https://github.com/Perl/perl5/issues/22118 and, on perl-5.39.9 devel release, went looking for the difference between calling builtin::stringify() and scalar().
This somewhat simplistic little script failed to find any difference:
use strict;
use warnings;
use experimental qw(builtin);
my @x = qw(one two three);
my $_1st = builtin::stringify @x;
my $_2nd = scalar @x;
print $_1st, "\n", $_2nd, "\n\n";
$_1st = builtin::stringify "@x";
$_2nd = scalar "@x";
print $_1st, "\n", $_2nd, "\n\n";
print builtin::stringify @x, "\n";
print scalar @x, "\n\n";
print builtin::stringify "@x", "\n";
print scalar "@x", "\n\n";
# UPDATE: remove duplicate test
#print builtin::stringify @x, "\n";
#print scalar @x, "\n\n";
There is a site I manage which is a good candidate for a forum. Here's what I'm after:
Written in Perl (of course)
Threaded discussions
Backed by an open source DB or similarly open storage mechanism
At least some sort of moderation system
Hopefully that's not too much to ask for. If you know of (or even better, use) such an application please reply with the details.
And yes, I do realise I'm asking this on precisely the type of platform I'm looking for but the gods and pmdevs constantly moan about how unmaintainable it is so perhaps it isn't a great option from a backend point of view. It is lovely to use as a normie, though. :-)
What I am looking is to see if someone has a quick solution to this. My approach would be to read each line, store the ID and the line of names, split the names using - as delimiter, put all names into an temp array on the fly and then make this array unique and print the unique elements.
Any more clever solution perhaps?
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 ;-)
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
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).