Let me explain my goal.
Let's say I have a file with a set of paths to files:
/usr/lib32/libssl.so
/usr/lib32/libz.so
...
and so on.
What's an easy way in perl to turn that input into:
/usr/lib32/libssl.so /usr/lib32/libssl.so
/usr/lib32/libz.so /usr/lib32/libz.so
...
Basically duplicate every string to the same line, delimited by a space?
Thanks for any assistance. I use perl's regex regularly for substitutions and the like (instead of using sed) and I prefer PCRE to sed. That said, not familiar with a way to do this.
submitted by /u/ShiningRaion
[link] [comments]
I have the pleasure to announce the release of the new Perl module DateTime::Format::RelativeTime
, which is designed to mirror its equivalent Web API Intl.RelativeTimeFormat
It requires only Perl v5.10.1
to run, and uses an exception class to return error or to die (if the option fatal
is provided and set to a true value).
You can use it the same way as the Web API:
```perl use DateTime::Format::RelativeTime; my $fmt = DateTime::Format::RelativeTime->new( # You can use en-GB (Unicode / web-style) or en_GB (system-style), it does not matter. 'en_GB', { localeMatcher => 'best fit', # see getNumberingSystems() in Locale::Intl for the supported number systems numberingSystem => 'latn', # Possible values are: long, short or narrow style => 'short', # Possible values are: always or auto numeric => 'always', }, ) || die( DateTime::Format::RelativeTime->error );
# Format relative time using negative value (-1). $fmt->format( -1, 'day' ); # "1 day ago" # Format relative time using positive value (1). $fmt->format( 1, 'day' ); # "in 1 day"
```
This will work with 222 possible locales
as supported by the Unicode CLDR (Common Locale Data Repository). The CLDR data (currently the Unicode version 46.1
) is made accessible via another module I created a few months ago: Locale::Unicode::Data
However, beyond the standard options, and parameters you can pass to the methods format
and formatToParts
(or format_to_parts
if you prefer), you can also provide 1 or 2 DateTime
objects, and DateTime::Format::RelativeTime
will figure out for you the greatest difference between the 2 objects.
If you provide only 1 DateTime
object, DateTime::Format::RelativeTime
will instantiate a second one with DateTime->now
and using the first DateTime
object time_zone
value.
For example:
perl my $dt = DateTime->new( year => 2024, month => 8, day => 15, ); $fmt->format( $dt ); # Assuming today is 2024-12-31, this would return: "1 qtr. ago"
or, with 2 DateTime
objects:
```perl my $dt = DateTime->new( year => 2024, month => 8, day => 15, ); my $dt2 = DateTime->new( year => 2022, month => 2, day => 22, ); $fmt->format( $dt => $dt2 ); # "2 yr. ago"
```
When using the method formatToParts
(or format_to_parts
) you will receive an array reference of hash reference making it easy to customise and handle as you wish. For example:
perl use DateTime::Format::RelativeTime; use Data::Pretty qw( dump ); my $fmt = new DateTime::Format::RelativeTime( 'en', { numeric => 'auto' }); my $parts = $fmt->formatToParts( 10, 'seconds' ); say dump( $parts );
would yield:
perl [ { type => "literal", value => "in " }, { type => "integer", unit => "second", value => 10 }, { type => "literal", value => " seconds" }, ]
You can use negative number to indicate the past, and you can also use decimals, such as:
my $parts = $fmt->formatToParts( -12.5, 'hours' ); say dump( $parts );
would yield:
perl [ { type => "integer", unit => "hour", value => 12 }, { type => "decimal", unit => "hour", value => "." }, { type => "fraction", unit => "hour", value => 5 }, { type => "literal", value => " hours ago" }, ]
The possible units
are: year
, quarter
, month
, week
, day
, hour
, minute
, and second
, and those can be provided in singular or plural form.
Of course, you can choose a different numbering system than the default latn
, i.e. numbers from 0
to 9
, as long as the numbering system you want to use is of numeric
type. There are 77 of those our of 96 in the CLDR data. See the method number_system
in Locale::Unicode::Data for more information.
So, for example:
perl use DateTime::Format::RelativeTime; use Data::Pretty qw( dump ); my $fmt = new DateTime::Format::RelativeTime( 'ar', { numeric => 'auto' }); my $parts = $fmt->formatToParts( -3, 'minutes' ); say dump( $parts );
would yield:
perl [ { type => "literal", value => "قبل " }, { type => "integer", value => '٣', unit => "minute" }, { type => "literal", value => " دقائق" }, ]
or, here we are explicitly setting the numbering system to deva
, which is not a system default:
perl use DateTime::Format::RelativeTime; use Data::Pretty qw( dump ); my $fmt = new DateTime::Format::RelativeTime( 'hi-IN', { numeric => 'auto', numberingSystem => 'deva' }); my $parts = $fmt->formatToParts( -3.5, 'minutes' ); say dump( $parts );
would yield:
perl [ { type => "integer", value => '३', unit => "minute" }, { type => "decimal", value => ".", unit => "minute" }, { type => "fraction", value => '५', unit => "minute" }, { type => "literal", value => " मिनट पहले" }, ]
The option numeric
can be set to auto
or always
. If it is on auto
, the API will check if it can find a time relative term, such as today
or yesterday
instead of returning in 0 day
or 1 day ago
. If it is set to always
, then the API will always return a format involving a number like the ones I just mentioned.
I hope you will enjoy this module, and that it will be useful to you. I have spent quite a bit of time putting it together, and it has been rigorously tested. If you see any bugs, or opportunities for improvement, kindly submit an issue on Gitlab
submitted by /u/jacktokyo
[link] [comments]
The Perl Data Language (PDL) has its own Advent Calendar apart from the Perl Advent Calendar.
PDL Advent site (calendar view)
- December 1 - What is Perl Data Language?
- December 2 - Maps with Perl Data Language
- December 3 - Perl Data Language on the Mac
- December 4 - (thread) Interpolation with Perl Data Language
- December 5
- December 6
- December 7
- December 8
- December 9
- December 10
- December 11
- December 12
- December 13
- December 14
- December 15
- December 16
- December 17
- December 18
- December 19
- December 20
- December 21
- December 22
- December 23
- December 24
- December 25
submitted by /u/briandfoy
[link] [comments]
Mo utilities for email.
Changes for 0.02 - 2024-04-26T23:02:53+02:00
- Add tests for error parameters.
- Rewrite the tests so that the functional tests are first and then the errors.
Perl.social Code of Conduct
I've posted this on reddit and wanted a discussion here too for those not on reddit for whatever reason:
reddit.com/r/perl/comments/1bl…
The gist though is that I've gotten another request for a proper CoC/ToS that would be acceptable to the community since i've been negligent in doing so. I've decided that a slightly modified version from the mastodon CoC might be a good starting point and I'll post that content in a reply to this so that it doesn't flood everyone's feeds with a giant wall of text immediately.
So hear me out...
This idea is stupid. But on Star Trek (VOY, TNG, and DS9 at least), they measured their data as "quads". ( memory-alpha.fandom.com/wiki/Q… ). This was never defined because it's just Sci-Fi and doesn't need a real definition. But... what if they're quad-floats aka 128bit floating point values. This would mean then that all the storage could be done as LLM or other neural network style models, and vector embeddings and such. Given what we've got today with transformer style models for doing translation, chat, etc. If you had ultrapowerful computers that could do these calculations with such gigantic precision then you'd be able to store very accurate data and transform it back and forth from vector embeddings and other fancy structures. It'd enable very powerful searches, and the kind of analysis we're trying to use LLMs for and see them use in the shows when talking to the computers. This would also explain a lot about the universal translators from ENG onward, and could even help make sense of Darmok and Jalad at Tenagra. And then Voyager even has bio-neural circuitry for doing things faster, some kind of organic analog computing doing stuff "at the edge". Using weights and embeddings to do things with them and have them react by programming them with a machine learning model at each node could easily explain how that could work too.
This idea honestly feels too stupid to be real but it could explain so much.
Perl.social server upgrades
Ryan Voots
in reply to Ryan Voots • •COC/TOS
Borrowing many things from the Mastodon CoC as a astarting point (github.com/mastodon/mastodon/b…).
I am removing a few things from it, not because I don't think they're good ideas or anything but also because I want to limit the scope
of the initial discussion and the amount of work for myself as I'm still currently the only moderator but once the community there gets larger
or it changes that I'm not the only one maintaining things, we will hold another discussion about everything.
I've changed a few things also, specifically to add stronger language that any moderators
MUST document why an action was taken. This doesn't necessarily mean that I believe
that those reasons must be immediately given to an affected user, but that they must
be available when requested. Specifically I'm thinking of not informing in the context
of bots, spam, illegal or otherwise legally actionable content (i.e. something that's going to get me a subpeona or court case).
Other proposed ideas:
1) Some kind of regular discussion, maybe annually? on ToS/CoC type things
1a) The idea being that we require a regular discussion of anything that's
happened over the last time period to avoid it being possible for something
happening being "swept under the rug" or "falling through the cracks" because
it didn't get the proper time given to it previously. How this should be done
I have no good recommendations for, likely creating a group on perl.social to
host the conversation each time?
2) ?
Contributor Covenant Code of Conduct
Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
Privacy
I reserve the right to collect email or other identifiable contact information,
and it will never be shared to an outside party without consent except in the case
of it being required by some legal process. If at any time perl.social becomes
a larger organization and there is a desire to change this, I will require the
removal of all such information until explicit consent is given again with such
a new policy. I don't know if there's a way I can make this legally enforcable
but I see it as something I do not own and therefore cannot ethically give it to
another party in that kind of scenario.
Both perl.social and I are located in the USA, and therefore I believe are not
directly subject to the GDPR, but as there are similar laws in other jurisdictions
even within the USA, and I basically agree with the ideas involved, I will do
whatever is reasonable feasible to follow them.
Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
and learning from the experience
community
Examples of unacceptable behavior include:
and sexual attention or advances of any kind. Consenting adults in private
should be acceptable.
without their explicit permission
professional setting
Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and MUST communicate reasons for moderation
decisions.
Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[hello@joinmastodon.org](mailto:hello@joinmastodon.org).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
1. Correction
Community Impact: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
Consequence: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
2. Warning
Community Impact: A violation through a single incident or series of
actions.
Consequence: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
3. Temporary Ban
Community Impact: A serious violation of community standards, including
sustained inappropriate behavior.
Consequence: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
4. Permanent Ban
Community Impact: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
Consequence: A permanent ban from any sort of public interaction within the
community.
Attribution
This Code of Conduct is adapted from the Contributor Covenant,
version 2.1, available at
contributor-covenant.org/versi…contributor-covenant.org/versi….
And from the Mastodon code of conduct available at github.com/mastodon/mastodon/b…
Community Impact Guidelines were inspired by
Mozilla's code of conduct enforcement ladder.
For answers to common questions about this code of conduct, see the FAQ at
contributor-covenant.org/faqcontributor-covenant.org/faq. Translations are available at
contributor-covenant.org/trans…contributor-covenant.org/trans….