I was using my $tmp = glob("file20240101.*") to find the full filename regardless of the extension(I knew there was only one of each file), when I found glob was alternating between working and failing
Rendering it as my ($tmp) = glob("file20240101.*") fixed the problem, but I'm wondering why, If it was going to go wrong I'd have thought treating glob's list in a scalar context would return the number of elements in the list
#!/usr/bin/perl
use warnings;
use strict;
for (1..4) {
my $tmp = glob($0);
print "$_ $tmp\n";
}
print "###\n";
for (1..4) {
my ($tmp) = glob($0);
print "$_ $tmp\n";
}
Output:
1 glob.pl
Use of uninitialized value $tmp in concatenation (.) or string at glob.pl line 7.
2
3 glob.pl
Use of uninitialized value $tmp in concatenation (.) or string at glob.pl line 7.
4
###
1 glob.pl
2 glob.pl
3 glob.pl
4 glob.pl
submitted by /u/octobod
[link] [comments]
Hi,
I don't get why this produces a syntax error:
my %r = map { "a$_" => 1 } qw(q w);
yet this works:
my %r = map { "a" . $_ => 1 } qw(q w);
What is going on here?
submitted by /u/ghiste
[link] [comments]
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]
Why is there not an option to sort search results by something like most recent update?
submitted by /u/int21
[link] [comments]
perl.com is always looking for quality content. It's quite easy to get started. You can even re-purpose an existing article if you think it fits the format. Thanks to David Farrell for making it easy with this getting started tutorial.
perl.com/article/how-to-write-…
submitted by /u/oalders
[link] [comments]
I've created a Christmas coupon for a free copy of Leaning Perl Exercises. This runs from all day on December 25 from midnight to midnight UTC for the first 37 uses (happy birthday Perl!).
submitted by /u/briandfoy
[link] [comments]
I'm a sysadmin who has very little experience with perl (who am I kidding, none). I recently came across some legacy code that "broke" due to migrating systems which leads me to some questions. Specifically the problem had to do with UTF8 support. Our environment requires supporting french characters.
what are the pros and cons of using these two?:
# open(MAIL, "| /usr/sbin/sendmail -t -oi")
# use Net::SMTP;
postfix is installed on all systems in question. If it matters the old systems are rhel7 based and the new systems are rhel9 based.
In my attempts to troubleshot the code vs system issues - using NET::SMTP worked very well for me. But the Devs not wanting to update their code insist I find a solution for their old sendmail version. That was done by setting postfix to "smtputf8_enable = no".
So what are the pros and cons of each method?
What are use cases for one over the other?
Are there other better modern ways of sending email either with perl directly or by using the systems smtp app?
submitted by /u/cwheeler33
[link] [comments]
I have no idea to what extent this is official, but GitHub is not updating any Perl package in the GitHub action runners. This is the current response to a request to post back LWP::protocol::https
which was there before, but vanished, needing an installation that takes a good amount of time.
submitted by /u/Sea-Bug2134
[link] [comments]
A big of blogging around Catalyst and handling complicated incoming request data.
dev.to/jjn1056/catalyst-tricks…
submitted by /u/jnapiorkowski
[link] [comments]
Recently I've decided to pick up Perl because it looked like a pretty cool language. The native regex, maturity, expressiveness, and strong unix ties is what gravitates me to the language. No shade on Python and the more popular languages, but I feel like Perl is a very capable language that doesn't get much love.
A language is just a tool. A tool used to get the job done. Now a particular tool may not be the "best" tool in the toolbox for the job, but that does not make it any less viable.
I've been doing some research on game development libraries with Perl, and came across some SDL bindings that I'm not quite sure are SDL1 or SDL2. But I believe they are SDL2 bindings. My confusion stems from seeing a particular software in the past versioning itself as v2 for the first predecessor/iteration of a software.
It doesn't appear to be actively maintained, but it does seem to be the best thing available for game development.
Can someone confirm this ?
submitted by /u/Warm-Scholar6106
[link] [comments]
grep-like code search tool ack has been updated to v3.8.0. It's available on CPAN as App::Ack, or at beyondgrep.com/
The big new feature is that you can have boolean matches on the line.
bash ack this --and that --and other and this --or that --or other ack this --not that --not other
submitted by /u/petdance
[link] [comments]
Hi everybody!
I am interested in learning the basics of programming in general, and I am looking for a good first language. I am very impressed by perl's abilities in formatting strings, something which is very difficult in C. Does perl not teach something necessary about general programming? I am not looking to learn OOP or functional programming specifically, just to get the basics down. I can then adapt these basics to other languages. So, has anyone learnt perl as their first language? Why would one recommend against it? I want to hear your opinions. Thank you for reading all this!
My thanks!
submitted by /u/chrisonlinux
[link] [comments]
Dear all,
given the versatility of generative AI, I want to test it at home. And I would prefer being able to do this in Perl instead of having to master Python.
But: Are there any non-obsolete Perl packages that allow local LLM access? For example, the scripts on [the MiniCPM-V-2_6 page](https://huggingface.co/openbmb/MiniCPM-V-2\_6) don't look frightening, but how would those be translated into Perl?
Basically, my main interests are:
- multilingual text embedding (yes, I am dreaming of a Perl-powered RAG)
- access to an instruct model, e.g. for content augmentation
- if possible, OCR with higher accuracy than tesseract
Thank you very much.
submitted by /u/Patentsmatter
[link] [comments]
Is it possible in Perl to { = BEGIN } = END
so
sub some sub BEGING ...code... END
Having a non English keyboard makes the various []{}|\ more complex to enter:
\ is "7 + option + shift" on a MAC whereas on US keyboard most have their own key and it is pretty straightforward.
I try to experiment with various ways to to make this easier. Still haven't found my. sweet spot. This is just another attempt.
submitted by /u/NoeticIntelligence
[link] [comments]