Skip to main content



[aside] This is not a cross-post. Few days ago I asked the same thing on Stack Overflow, and there were several answers, but none of them works really perfect.)

I have a folder with the following files there:

1.mp3 1.mp3.mp4 1.mp4.mp3 1.txt 2.mp3 2.mp3.mp4 2.mp4.mp3 2.txt foo.mp3 foo.mp3.mp4 foo.mp4.mp3 foo.txt foo1.mp3 foo1.mp3.mp4 foo1.mp4.mp3 foo1.txt foo2.mp3 foo2.mp3.mp4 foo2.mp4.mp3 foo2.txt

Filenames like foo.mp4.mp3 mean that originally the file was MP4 and later converted to MP3.

I need to batch rename MP3 files there, so that their numbers will be padded with leading zeros, that is, 1.mp3 should be renamed 0001.mp3, 1.mp4.mp3 to 0001.mp4.mp3, foo1.mp3 to foo001.mp3, and so on.

Here are several attempts by other people:

  • rename -n 's/(\d+)/sprintf "%03d", $1/e' *.mp3
  • rename -n 's/(\d+)\.mp3/sprintf "%03d.mp3", $1/e' *.mp3
  • rename -n 's/(\d+)(\.mp3)/sprintf("%03d", $1) . $2/e or s/(\d+)(\.mp3)/sprintf "%03d%s", $1, $2/e' *.mp3
  • rename -n 's/(\d+)(\.mp3)/sprintf "%03d%s", $1, $2/e' *.mp3
  • rename -n 's/(\d+)(?=\.mp3)/sprintf "%03d", $1/e' *.mp3
  • and my own, doesn't work either: rename -n 's/(\d)(\.[^.]+)/sprintf "%03d%s", $1, $2/e' *

Maybe there is a Perl wizard here who could help me?

submitted by /u/Impressive-West-5839
[link] [comments]



Hello Perl Community. I was trying to build a secure string library in C resistant to buffer overflow vulnerabilities when I realized parsing inputs matters. Perl is well known for string rendering. What books would you recoendnd to a proficient C coder that is trying to learn Perl to master the art of parsing and editing strings to avoid common security exploits?

submitted by /u/fosres
[link] [comments]




Reasoning About the Rigor of Perl Programs - George Baugh - TPRC 2024 submitted by /u/briandfoy
[link] [comments]





I have a Mac M1 chip laptop.

While I have managed to install a couple of modules, most fail to install.

I tried perlbrew, but that was a struggle to even get it to install perl itself, but when it was installed it wasn't working the way I needed it to.

Just wondering if I am missing something with CPAN or if this is an issue because it's an M1 chip?

submitted by /u/MrCosgrove2
[link] [comments]




The final installment in the series:

"The-Quest-For-Performance" from my blog Killing It with #perl

Discussing #python #numpy #numba, #rstats #openMP enhancements of Perl code and #simd

Bottom line: I will not be migrating to Python anytime soon.

Food for thought: The Perl interpreter (and many of the modules) are deep down massive C programs. Perhaps one can squeeze real performance kicks by looking into alternative compilers, compiler flags and pragmas ?

https://chrisarg.github.io/Killing-It-with-PERL/2024/07/09/The-Quest-For-Performance-Part-IV-May-the-SIMD-Force-Be-With-You.html

submitted by /u/ReplacementSlight413
[link] [comments]






I would be interested to know why you chose Perl and how long you have been using it and what for.

I have just returned to Perl after many years away, think decades rather than a couple of years. Consider me a noob as I've long forgotten anything I knew about the language.

I run a small home webserver, Apache on Windows 10 with Strawberry Perl, and recently started some projects starting with moving away with things like Google Analytics and going back to some old log analyzers such as AWStats, which is still being maintained, and W3Perl, which is not. Even more recently I have started using Ringlink.

Perl is still being developed, Strawberry, Active State, CPAN etc. but lost out to PHP and Python. Just like COBOL, I can easily imagine thousands of systems depend on Perl.

submitted by /u/brisray
[link] [comments]





Have been using the official MongoDB driver to date (https://metacpan.org/dist/MongoDB) but its obviously EOL and now I can't get it to work with perl v.540 on OSX.

For those interested it fails on BSON::XS and I cannot force install either.

cp XS/XS.xs blib/lib/BSON/XS/XS.xs Running Mkbootstrap for XS () chmod 644 "XS.bs" "/usr/local/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- XS.bs blib/arch/auto/BSON/XS/XS.bs 644 "/usr/local/bin/perl" "/usr/local/lib/perl5/5.40.0/ExtUtils/xsubpp" -typemap '/usr/local/lib/perl5/5.40.0/ExtUtils/typemap' xs/XS.xs > xs/XS.xsc mv xs/XS.xsc xs/XS.c cc -c -I. -Ibson -fno-common -DPERL_DARWIN -mmacosx-version-min=14.5 -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_GNU_SOURCE -DMONGO_USE_64_BIT_INT -DBSON_COMPILATION -Wno-error=implicit-function-declaration -O3 -DVERSION=\"v0.8.4\" -DXS_VERSION=\"v0.8.4\" -o xs/XS.o "-I/usr/local/lib/perl5/5.40.0/darwin-2level/CORE" xs/XS.c xs/XS.xs:216:3: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro] PUSHMARK (SP); ^~~~~~~~~~~~~ /usr/local/lib/perl5/5.40.0/darwin-2level/CORE/pp.h:120:5: note: expanded from macro 'PUSHMARK' STMT_START { \ ^~~~~~~~~~ ./ppport.h:4305:31: note: expanded from macro 'STMT_START' # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ ^ xs/XS.xs:216:3: note: '{' token is here PUSHMARK (SP); ^~~~~~~~~~~~~ /usr/local/lib/perl5/5.40.0/darwin-2level/CORE/pp.h:120:16: note: expanded from macro 'PUSHMARK' STMT_START { \ ^ xs/XS.xs:216:3: warning: '}' and ')' tokens terminating statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro] PUSHMARK (SP); ^~~~~~~~~~~~~ /usr/local/lib/perl5/5.40.0/darwin-2level/CORE/pp.h:129:5: note: expanded from macro 'PUSHMARK' } STMT_END ^ 

With that said, whats the most appropriate alternative out there?

submitted by /u/kosaromepr
[link] [comments]



A couple of data/compute intensive examples using Perl Data Language (#PDL), #OpenMP, #Perl, Inline and #Python (base, #numpy, #numba). Kind of interesting to see Python eat Perl's dust and PDL being equal to numpy.

OpenMP and Perl's multithreaded #PDL array language were the clear winners here.


https://chrisarg.github.io/Killing-It-with-PERL/2024/07/06/The-Quest-For-Performance-Part-I-InlineC-OpenMP-PDL.html

https://chrisarg.github.io/Killing-It-with-PERL/2024/07/07/The-Quest-For-Performance-Part-II-PerlVsPython.md.html

submitted by /u/ReplacementSlight413
[link] [comments]



Hello all. I installed Perlbrew to try it out using Perl modules without admin rights. My machine is Linux EOS. When I run a simple perl script it gives error Cant locate Modern/Perl.pm in \@INC. How do I make Emacs know that I am using perlbrew and not system Perl? Or how do add the perlbrew PATH to global \@INC? I also have setup Devel::PerlySense inside Emacs following the module documentation. I installed some modules using cpanm client. I'm new to Perl and Emacs and sometimes I'm lost n doesnt know what I'm doing lol 😀 Appreciate your pointing me to the right direction. Below are some log details:


Can't locate Modern/Perl.pm in u/INC (you may need to install the Modern::Perl module) (@INC entries checked: /usr/lib/perl5/5.38/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/5.38/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/5.38/core_perl /usr/share/perl5/core_perl) at ./read_input_stdin line 4.

BEGIN failed--compilation aborted at ./read_input_stdin line 4.

❯ perlbrew info

Current perl:

Name: perl-blead

Path: /home/user/perl5/perlbrew/perls/perl-blead/bin/perl

Config: -de -Dprefix=/home/user/perl5/perlbrew/perls/perl-blead -Dusedevel -Aeval:scriptdir=/home/user/perl5/perlbrew/perls/perl-blead/bin

Compiled at: Jul 6 2024 10:50:31

perlbrew:

version: 0.98

ENV:

PERLBREW_ROOT: /home/user/perl5/perlbrew

PERLBREW_HOME: /home/user/.perlbrew

PERLBREW_PATH: /home/user/perl5/perlbrew/bin:/home/user/perl5/perlbrew/perls/perl-blead/bin

PERLBREW_MANPATH: /home/user/perl5/perlbrew/perls/perl-blead/man

❯ perl --version

This is perl 5, version 41, subversion 2 (v5.41.2 (c5df4fd1012cc64d1b3e19c87bf8c51d4f3f90d6)) built for x86_64-linux

❯ perlbrew list-modules | grep modern

Modern::Perl

submitted by /u/Ill-Dependent2628
[link] [comments]



submitted by /u/davorg
[link] [comments]





Building an OpenAI chatbot in Corinna submitted by /u/OvidPerl
[link] [comments]



I am fairly new to Perl. I did a lot with it in the mid 90s and came back about 8 months ago. There is a lot I dont know and probably a lot of things I have forgotten.

I picked up Perl to write a couple of applications that I was hoping could run on MacOS, Linux,OpenBSD, and Windows. Perl runs on all of them and many come with Perl built in. Simple scripts I have written run pretty well. (Lets forget about Windows for now).

When I start using libraries(packages?) there is a world of hurt.

Now some libraries pretty much usually work, but many do not. Which works and which do not seems to be dependent upon the operating system and distro.

Then I have to start with what version of Perl is running everywhere. That is annoying.

I end up spending a lot of time on a new machine when I want to run my application, doing nothing else than trying to get the libraries installed.

So I decided to adopt PerlBrew (havent tried it on OpenBSD yet) That should give me a stable version across the differnt platforms.

Then I decided I wanted to write a shell script that would handle installing all of the libarires I might use once and for all so I would know they were all accounted for.

perlbrew exec -q --with perl-5.40.0 cpanm install DBI

Then libraries I have pulled from CPAN do not work.

Google here and Google there.

Ok install GCC and make (I should have known this) More problems:

I found a few of these: "Why are you using CPAN for this? Use the compiled packages that come with <OS><type>"

Hmm I would have thought that CPAN shold be the best source? How do I know what exists as pre built packages on what platform?

Using apt search "perl" or "-perl" or "perl" does not help that much.

I have XML::LibXML working on Mac but getting it working on Ubuntu 22 I have been able to do. I have even tried to start OpenBSD yet)

Is writing cross platform applications in Perl meant to be this difficult?

Should I avoid libraries at all costs and write an aweful lot of code myself?

Is there an easy way to guess what libraries will almost certainly work and what libraries will most likely never work? Some kind of warning system?

Should I look into using pp? I havent yet figured out how to make it compile for Ubuntu,MacOs,OpenBSD yet.

In GoLang its a couple of flags to set for each architecture and off it goes.

ShouldI look into Par files? (or was it Far) that are supposesd to contain the nessescary libraries within itself?

What am I doing wrong?

Libraries in my current set Given all the experimenting some of them are now wrong.

Array::Set, Array::Unique, Bundle::LWP, Data::Dump, Data::Dumper, DateTime, DBD::SQLite, DBI, Digest::file, Digest::MD5, Digest::MD5::File, File::Basename, File::Compare, File::Copy, File::Find, File::Find::Rule, File::Glob, File::Path, File::Slurp, File::Spec, Image::ExifTool, Image::Info, IO::All, List::Compare, List::Gen, List::MoreUtils, List::SomeUtils, List::Util, List::UtilsBy, Log::Minimal, LWP, LWP::Simple, Path::Tiny, Term::ANSIColor, Text::Fuzzy, Type::Tiny,Moose,MooseX::Types,WWW::Mechanize

submitted by /u/NoeticIntelligence
[link] [comments]






You may have noticed the slow pace of Corinna development. As it turns out, there's an easy way to speed up the development: tell Paul.

I had a call with Paul "LeoNerd" Evans last night and this, including his email address, is being shared with his permission.

As you might imagine, being a core Perl developer, Paul has many things on his plate. Currently has has tons of PRs against the Perl core, he's doing new work such as experimenting with data checks (don't call them "types"!), and is active on the Perl steering council and in P5P. However, he's previously mentioned that he doesn't get much feedback on his work. For adding something as important as Corinna, just blindly adding it without hearing from the community is bad. Yes, we had a multi-year design phase and Corinna is much better for it, but that doesn't mean it's perfect and we don't want to screw this up.

So here's where you come in. Email Paul at leonerd at leonerd.org.uk. Tell him your thoughts about Corinna. He's he one implementing it and working in isolation as he is, despite his work with Object::Pad, isn't good. Tell him what you like, what you don't like, what you'd like to see next, what bugs you've encountered, and so on. Without hearing from you, he has no way of judging community thoughts/support for this project, so he needs your help.

If you'd like a quick refresher on the new syntax, I've written a short introduction. Here's a dead-simple LRU cache written in the new syntax:

use feature 'class'; class Cache::LRU { use Hash::Ordered; field $cache = Hash::Ordered->new; field $max_size :param :reader = 20; method set( $key, $value ) { $cache->unshift( $key, $value ); # new values in front if ( $cache->keys > $max_size ) { $cache->pop; } } method get($key) { return unless $cache->exists($key); my $value = $cache->get($key); $cache->unshift( $key, $value ); # put it at the front return $value; } } 

submitted by /u/OvidPerl
[link] [comments]







My job has led me down the rabbit hole of doing some scripting work in Perl, mainly utility tools. The challenge being that these tools need to parse several thousand source files, and doing so would take quite some time.

I initially dabbled in doing very light stuff with a perl -e one-liner from within a shell script, which meant I could use xargs. However, as my parsing needs evolved on the Perl side of things, I ended up switching to an actual Perl file, which hindered my ability to do parallel processing as our VMs did not have the Perl interpreter built with threads support. In addition, installation of any non-builtin modules such as CPAN was not possible on my target system, so I had limited possibilities, some of which I would assume to be safer and/or less quirky than this.

So then I came up with a rather ugly solution which involved invoking xargs via backticks, which then called a perl one-liner (again) for doing the more computation-heavy parts, xargs splitting the array to process into argument batches for each mini-program to process. It looked like this thus far:

my $out = `echo "$str_in" | xargs -P $num_threads -n $chunk_size perl -e ' my \@args = \@ARGV; foreach my \$arg (\@args) { for my \$idx (1 .. 100000) { my \$var = \$idx; } print "\$arg\n"; } '`; 

However, this had some drawbacks:
  • No editor syntax highlighting (in my case, VSCode), since the inline program is a string.
  • All variables within the inline program had to be escaped so as not to be interpolated themselves, which hindered readability quite a bit.
  • Every time you would want to use this technique in different parts of the code, you'd have to copy-paste the entire shell command together with the mini-program, even if that very logic was somewhere else in your code.

After some playing around, I've come to a nifty almost-metaprogramming solution, which isn't perfect still, but fits my needs decently well:

sub processing_fct { my u/args = u/ARGV; foreach my $arg (@args) { for my $idx (1 .. 100000) { my $var = $idx; } print "A very extraordinarily long string that contains $arg words and beyond\n"; } } sub parallel_invoke { use POSIX qw{ceil}; my $src_file = $0; my $fct_name = shift; my $input_arg_array = shift; my $n_threads = shift; my $str_in = join("\n", @{$input_arg_array}); my $chunk_size = ceil(@{$input_arg_array} / $n_threads); open(my $src_fh, "<", $src_file) or die("parallel_invoke(): Unable to open source file"); my $src_content = do { local $/; <$src_fh> }; my $fct_body = ($src_content =~ /sub\s+$fct_name\s*({((?:[^}{]*(?1)?)*+)})/m)[1] or die("Unable to find function $fct_name in source file"); return `echo '$str_in' | xargs -P $n_threads -n $chunk_size perl -e '$fct_body'`; } my $out = parallel_invoke("processing_fct", \@array, $num_threads); 

All parallel_invoke() does is open it's own source file, finds the subroutine declaration, and then passes the function body captured by the regex (which isn't too pretty, but it was necessary to reliably match a balanced construct of nested brackets) - to the xargs perl call.

My limited benchmarking has found this to be as fast if not faster than the perl-with-threads equivalent, in addition to circumventing the performance penalty for the thread safety.

I'd be curious to hear of your opinion of such method, or if you've solved a similar issue differently.

submitted by /u/Wynaan
[link] [comments]



List of new CPAN distributions – Jun 2024 submitted by /u/perlancar
[link] [comments]


I need some help with the old Perl Gunnar Hjalmarsson's Ringlink program on my site. The forms work, the database gets added to and everything seems ready to go except for the email functions that depend on sendmail.

I have tried several things, installed the CPAN dependencies the program needs, tried Auron SendEmail and other programs and have thoroughly confused myself.

There's a test installation on my site, with the admin and password are both 'test'. There are copies of the CGI files and probably what needs looking at are rlmain.pm, rlconfig.pm and sender.pm

I am running Apache 2.4.54 on Windows 10 with Strawberry Perl installed. I am using the last published version Ringlink (v3.4)

I know this is an old program and the project probably not worth pursuing, but I really would like to give this a go to get it working and would be grateful for any suggestions.

submitted by /u/brisray
[link] [comments]



submitted by /u/niceperl
[link] [comments]



The Once and Future Perl

Damian on top form as always. The modules this talk is based on are, of course, all both brilliant and incredibly useful. But the thing that's really impressed me here is the way he has taken some of his modules from a couple of decades ago and replaced them with calls to LLMs. That's food for thought.

submitted by /u/davorg
[link] [comments]



Visual Exploration of Perl Camel at TPRC 24 ConferenceI was lucky enough to attend the perl and raku conference this year and had a great time meeting lots of awesome people.

I am primarily a designer by trade but do code as well. At the conference, I explored a number of original depictions of the perl camel for fun and this one was my favorite. The idea was to bring a strikingly modern feel to the Perl Camel. Loose inspiration for this symbol is code llama and p****n. This design exploration felt like my way to hack something during the conference!

The idea behind this simple symbol is that it could work nicely at very small sizes while still being visually clear. The font is a free open-source display font called Jaro. the first image was also a concept of placing "Perl" in the camel symbol to strengthen the association between the "perl" and the camel symbol as this may be helpful for new developers. I could spend much more time on this but thought I would share!

Love it? Hate it? Let me know what you think (especially if you like it)

https://preview.redd.it/ce8225s3dc9d1.png?width=5256&format=png&auto=webp&s=10a3c3ed4e0c9aea3f46d61308b75879be1d98e5

submitted by /u/North-Clue-2313
[link] [comments]







PSA: to get Net::SSLeay to build on a new M3 MBP I had to do export OPENSSL_PREFIX=/opt/homebrew/opt/openssl/include/openssl/ to get it to build on a new M3 MBP with an OpenSSL that was installed via brew install openssl

Filed an issue at https://github.com/radiator-software/p5-net-ssleay/issues/482

submitted by /u/lovela47
[link] [comments]



As the conference is happening in Las Vegas right now, recordings of the talks are being posted to YouTube.

https://www.youtube.com/@YAPCNA

Thanks to everyone planning, sponsoring, speaking and coding in the Perl space. I appreciate you all.

submitted by /u/DeepFriedDinosaur
[link] [comments]



My site got exploited the other week. I had a backup of my WordPress domain, so after importing the backup, most of the infected files were gone. However, some files outside the public_html folder were infected. I deleted those files, and my website loads up fine. Just wondering, is there a way I can restore those files without having my hosting company reinstall Perl?

Thx in advance.

/home2/user1/perl5/lib/perl5/x/index.php: SL-PHP-FILEHACKER-fbo.UNOFFICIAL FOUND

/home2/user1/perl5/lib/x/index.php: SL-PHP-FILEHACKER-fbo.UNOFFICIAL FOUND

/home2/user1/perl5/bin/x/index.php: SL-PHP-FILEHACKER-fbo.UNOFFICIAL FOUND

/home2/user1/perl5/x/index.php: SL-PHP-FILEHACKER-fbo.UNOFFICIAL FOUND

-ABS

submitted by /u/AnotherBrokenSpirit
[link] [comments]



Sorry I didn't get this out here earlier (and it's an xpost from Perlmonks), but Perl Community (parent org of the Science Perl Committee that is initiated the Science Track) is giving out a "peoples choice" award at the end of Conference Lightning Talks. It's sincere gesture from us and allows anyone to vote for anyone in the Perl community at large, as a "thank you" from us.

link to Google voting form

The Science Track talks have been great, some are even starting to come online. Thanks to everyone who made this happen, especially the TPRC Planning Committee.

submitted by /u/OODLER577
[link] [comments]