I try to use Perl's rename
utility to translate filenames to lower case. I tried two different solutions, one from perldoc rename
and another from Perl Cookbook:
rename 'y/A-Z/a-z/' ./*
rename 'tr/A-Z/a-z/ unless /^Make/' *.txt
But either version gives me an error because of complaining that file with such a filename already exists:
./fOoBaR.tXt not renamed: ./foobar.txt already exists
How to make it work?
submitted by /u/Impressive-West-5839
[link] [comments]
While refactoring some code with the usual desire to improve/simplify, I came by this interesting example on S.O. that uses the dispatch table structure:
ref _ stackoverflow.com/questions/84…
my $switch = { 'case1' => sub { print "case1"; }, 'case2' => sub { print "case2"; }, 'default' => sub { print "unrecognized"; } }; $switch->{$case} ? $switch->{$case}->() : $switch->{'default'}->(); #($switch->{$case} || $switch->{default})->() # ephemient's alternative
Dispatch tables are powerful and I use them often.
Gabor Szabo offered a post with an example of given/when, but in the end he suggests just using the if/else construct.
given ($num) { when ($_ > 0.7) { say "$_ is larger than 0.7"; } when ($_ > 0.4) { say "$_ is larger than 0.4"; } default { say "$_ is something else"; } }
ref _ perlmaven.com/switch-case-stat…
= = =
Which approach do you prefer? Or do you prefer some other solution? Saying no to all the above is a viable response too.
submitted by /u/singe
[link] [comments]
perl -CADS -le 'print $ARGV[0]' -- -v=αβγ -v=αβγ perl -CADS -sle 'print $v' -- -v=αβγ αβγ
submitted by /u/appomsk
[link] [comments]
Although this StackOverflow question about "islands and gaps" is titularly about Perl, the SQL answers are very nice. Apparently this is a FAQ for SQL.
However, this has bugged me for years on the CPAN side, but never enough to make me really do anthing about.
I thought there was a Perl module that did this, and it was in the context of a usenet reader that would take a list of article IDs, such as 1, 2, 3, 4, 5, 7, 10, 11, 15 and return something like 1-5,7,10-11,15
as a more space-efficient store of all the articles you had read.
Every time I've looked I've stopped after 15 minutes because I get distracted and I've never really needed this except to answer someone else's question. I'm not asking how to solve this because there are plenty of algorithm tutorials out there. Surely this is on CPAN somewhere.
There are plenty of options to go the other way and to ask if a number is in one of the ranges.
- Usenet was pre-web reddit, and comp.lang.perl and comp.lang.perl.misc are where I got my start in the Perl socials before there was "social".
submitted by /u/briandfoy
[link] [comments]
I am new to this subreddit, but not new to Perl, though I've been flirting with Python for a little over two years so I'm a little out of the loop.
If I wanted to create a RESTful API using Catalyst and have my Swagger docs generated automatically, are there any toolchain recommendations that anyone can make?
Thanks.
submitted by /u/Biggity_Biggity_Bong
[link] [comments]
This might be Perl/docker-perl#161 but if I filed this in the wrong place, let me know. Keeping these things current is the sort of thing I'd pay for.
Pulling perl images locally give the same warnings for old perl versions, although my local docker will still run them:
$ docker pull perl:5.14 5.14: Pulling from library/perl Image docker.io/library/perl:5.14 uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
Here's what I'm getting today from GitHub Actions. Sure, I see all sort of warnings to upgrade node, but nothing about this change:
/usr/bin/docker pull perl:5.14 5.14: Pulling from library/perl [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/perl:5.14 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/ Warning: Docker pull failed with exit code 1, back off 5.148 seconds before retry. /usr/bin/docker pull perl:5.14 5.14: Pulling from library/perl [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/perl:5.14 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/ Warning: Docker pull failed with exit code 1, back off 4.06 seconds before retry. /usr/bin/docker pull perl:5.14 5.14: Pulling from library/perl [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/perl:5.14 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/ Error: Docker pull failed with exit code 1
From this snippet in my GitHub workflows (e.g. .github/workflows/linux.yml)
matrix: os: - ubuntu-22.04 perl-version: - '5.8' - '5.10' - '5.12' - '5.14' - '5.16' - '5.18' - '5.20' - '5.22' - '5.24' - '5.26' - '5.28' - '5.30' - '5.32' - '5.34' - '5.36' - 'latest' container: image: perl:${{ matrix.perl-version }}
submitted by /u/briandfoy
[link] [comments]
I threw together a quick proof of concept for myself writing out a very simple Entity Component System (ECS) and implementing the flocking simulation on top of it. I liked how it came together so well I wrote some prose around it and decided to share. Note: this is using features from the soon-to-be-released 5.40.0 (RC1 dropped last Friday). submitted by /u/perigrin |
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.