Skip to main content



submitted by /u/Active-Fuel-49
[link] [comments]



http://Direct Access to PDF Internals with PDF::Data - Deven Corzine - TPRC 2024 submitted by /u/briandfoy
[link] [comments]


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 _ https://stackoverflow.com/questions/844616/obtain-a-switch-case-behaviour-in-perl-5


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 _ https://perlmaven.com/switch-case-statement-in-perl5

= = =

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]