If you've discovered something amazing about Perl that you just need to share with everyone, this is the right place.

This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)

Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").

User Meditations
How old is too old?
4 direct replies — Read more / Contribute
by Bod
on Apr 08, 2021 at 16:01

    Over on Re: How Xerces validation access http schemas ?, hippo wrote "It's worth noting that the most recent versions of XML::Validate and XML::Xerces are from 15 years ago and may not play so well with modern systems". This immediately reminded me of a recent search for modules to connect with PayPal where I found Business::PayPal::IPN but didn't look any further than the date which is AUG 19, 2003.

    Clearly for things that connect to frequently evolving APIs, being quite up to date is pretty important unless the API allows use of a particular past version. But for things that don't change much, like XML, the need for recent updates is less apparent. As hippo puts it, they need to "play well with modern systems".

    So, when deciding whether to use a module, or anything else for that matter, how old is too old?

[RFC] What is [pP]erl to you, and how has this changed for you over the years (if it has)?
3 direct replies — Read more / Contribute
by perlfan
on Mar 31, 2021 at 18:22
    I'm just as curious about the value of this exercise as I am the answers, but I wanted to request something. Originally, I wanted to as, is perl a unix utility or is it a language?. Then I realized, this has many dimensions and I'd rather not beg the continuum of answers upfront; but it's worth at least sharing this point. Anyway, this seems especially timely given the recent discussions on p5p and elsewhere about a whole lot of things related to [pP]erl.

    Some politely requested ground rules:

    • refrain from replying to anyone else (except OP)
    • please don't ++ OP, I'm not doing this for XP (-- if you must, that's not the ask)
    • upvote replies, this provides information/consensus
    • refrain from downvoting sincere replies, even trolls/rants (for real)
    • focus on your own perspective (this is not currently a debate or zero sum game)
    • feel free to post anonymously
    • post only once, feel free to edit/update your node as much as you want

    Okay, so why am I doing this? For the children. (Seriously, I have a follow up about "the future"; but be patient). I'll probably give that in a few weeks. TIA

[RFC] Review of module code and POD
6 direct replies — Read more / Contribute
by Bod
on Mar 31, 2021 at 15:45

    Esteemed Monks,

    For all past time we have connected directly to our CRM from the scripts that need to read or write the data. It has been my intention for a very long time to create some standard subroutines in a require file to do all the things we regularly need to do. Thanks to The Monastery, I now know I need to use a module to do this. So I have set about creating a suitable module. I also thought this would be a good opportunity to do it properly and include some POD. This module will never be used outside of our use case but it seems like good practice to include documentation.

    Could you please look over the code and documentation and for me before I go too much further and advise if I am making any horrible mistakes, what I can improve and how clear the documentation is...

    I have pulled out anything that could pose a security threat to Bod::Variables. Not just database username and password but also schema name and table names.

    The documentation as generated by pod2html is here.

I just had to share this (Quora comment on Python)
2 direct replies — Read more / Contribute
by ait
on Mar 29, 2021 at 13:49

    As I was reading some random old thread on "Why is Python so bad?" I came across this comment which I think reflects why I love Perl so much:

    Sudhir Sudhir
    July 29, 2019
    Python is considered bad because it suffocates you to death while being deaf to the prey’s death cries. It falls on you unexpected from the top of a tree and before it swallows you it has to crush your bones and make you a sack of pulp for easier consumption. Very painful. Won’t recommend at all. It’s not venomous, so you have no option of getting hallucinations through the painful experience before death either.

New RFC for CSV in the pipeline
1 direct reply — Read more / Contribute
by Tux
on Mar 16, 2021 at 09:07

    I wonder how much code would break if all of what RFC 4180bis proposes would be blindly implemented by parsers.

    I bet there are tons of CSV files out there that are not UTF-8 and/or do not follow BOM correctly or are real binary to start with.

    And what about point 8:

    A hash sign MAY be used to mark lines that are meant to be commented lines. A commented line can contain any whitespace or visible character until it is terminated by a line break (CR, LF or CRLF). A comment line MAY appear in any line of the file (before or after an OPTIONAL header) but MUST NOT be mistaken with a subsequent line of a multi-line field. Subsequent lines of multi-line fields can start with a hash sign and MUST NOT interpreted as comments. For example: #commentCRLF aaa,bbb,cccCRLF #comment 2CRLF "aaa","this is CRLF

    This would require new options in all parsers to reject lines that start with a #.

    As Text::CSV_XS already implements/supports all other options, I wonder if there would be enough motivation to add attributes to recognize/skip comments (which would also require a new config variable that contains the comment lead-in (#, // sprint to mind) and if a leading comment string would only be valid if followed by whitespace (probably more things to consider). This would also mean impact on strict as comments (and empty lines) will, per definition, nog have the same number of fields as the rest of the data.

    Ideas welcome as usual.


    Enjoy, Have FUN! H.Merijn
RFC: Kinda pseudo-shuffle using sort
3 direct replies — Read more / Contribute
by rsFalse
on Mar 15, 2021 at 05:58
    Hello.

    I'd like to share my observation how to shuffle an array with Perl's sort. This shuffle is far from perfect, and the result of shuffle isn't uniform. But may it be useful for someone.

    !!! UPD. Using sort subroutine in that way is NOT RECOMMENDED! See further comments. ikegami and haukex provided explanation and cited documentation. !!!

    Code:
    @array = sort { 0.5 <=> rand } @array;
    Perl's default sort algorithm is mergesort (perlsec: Algorithmic Complexity Attacks) from 5.8.0 version (Although there may be some optimizations or different behavior if an array length is less than 18? e.g. RFC: Simple switches for 'sort' and list 'reverse').
    How does it work? Sort subroutine ignores values of both elements of a pair to compare, i.e. we don't use bindings: nor $a neither $b. Just a constant and rand() function. Here rand() produces some number from an interval 0 to 1 and compares it to a constant (i.e. 0.5). And the "spaceship" operator returns either -1, either 1 (hence with 0.5 probability). Then sort, depending on subroutine's value, changes positions of elements of a pair.

    How the results obtained with this sort subroutine differ from uniformly shuffled array, e.g. Fisher-Yates shuffle?
Anyone interested in old Perl Journal and Perl Review magazines?
2 direct replies — Read more / Contribute
by iguanodon
on Mar 10, 2021 at 18:34
    Hi Monks, is anyone interested in old Perl Journal and Perl Review magazines? I will be moving and don't want to move these, again. I think I have a complete set of both:
    • The Perl Journal: 22 issues, spring 1996 through fall 2001
    • The Perl Review: 18 issues, winter 2004 through spring 2009
    I would rather give these away than throw them in the recycle bin. I'd prefer to give them to someone who will take one or both complete sets but if there is nobody interested in that I will send individual issues. If you will take a complete set I will ship them to anywhere in the US, free to a good home. Outside the US, let's talk :) .
RFC: Simple switches for 'sort' and list 'reverse'
2 direct replies — Read more / Contribute
by rsFalse
on Mar 05, 2021 at 11:32
    Upd. I slightly changed a node name and rewrote a section about reverse (older text is under strikethrough and moved to the end of the post).

    Rarely we want to do something the same with both: with original and reversed list, or with original and sorted (and sorted backwards) list. Here you will find few examples how to use a simple switch to turn ON/OFF sorting or reversing list.

    sort: Say we want to apply some function on original, sorted, and sorted backwards list. Example program:
    my @original = ( 5, 'A' .. 'C', 0, 4 ); my @sorted = sort sort_sub @original; my @r_sorted = reverse @sorted; some_sub( $_ ) for \@original, \@sorted, \@r_sorted; print '-';
    Now we use multiplicative "switch" to gain the same output:
    some_sub( [ sort { $_ * sort_sub } @original ] ) for 0, 1, -1; print '-';
    Note we avoided intermediate variables.
    reverse: Say we want to apply some function on original and reversed list. We can simply pass 0 or 1 into sort block:
    my @reversed = reverse @original; some_sub( $_ ) for \@original, \@reversed; print '-'; some_sub( [ sort { $_ } @original ] ) for 0, 1;
Banal Configuration Languages
1 direct reply — Read more / Contribute
by jdporter
on Feb 26, 2021 at 14:10

    This is so great, I have to share it here. This guy nails it on the head. (Spring, we're looking at you.)

    I suspect a lot of abuse of config files comes from moving logic out of source code for bad reasons. There are good reasons for not hard-coding, say, ports and service endpoints in your source code, because it makes it easier to run the code in different environments. However, there are also bad reasons for taking things out of code. A couple that I have encountered:

    Pride in creating a "generic" system that can be configured to do all kinds of new things "without touching the code." Reality check: only one or two programmers understand how to modify the config file, and changes have to go through the same life cycle as a code change, so you haven't gained anything. You've only made it harder to onboard new programmers to the project.

    Hope that if certain logic is encoded in config files, then it can never get complicated. Reality check: product requirements do not magically become simpler because of your implementation decisions. The config file will become as expressive as necessary to fulfill the requirements, and the code to translate the config file into runtime behavior will become much more complex than if you had coded the logic directly.

    Hope that you can get non-programmers to code review your business logic. Reality check: the DSL you embedded in your config file isn't as "human readable" as you think it is. Also, they're not going to sign up for a Github account and learn how to review a PR so they can do your job for you.

    Marketing your product as a "no code" solution. Reality check: none for you; this is great! Your customers, on the other hand, are going to find out that "no code" means "coding in something that was never meant to be a programming language."
RFC: Devel::Trace 0.13
No replies — Read more | Post response
by shmem
on Feb 25, 2021 at 17:41

    Years ago I posted at Devel::Trace - TODOs done, trace per package some enhancements for Devel::Trace by Dominus. A few days ago I stumbled over the fact that Dominus added me as maintainer on PAUSE. Oh my, oh my... what to do? what to do?

    So I decided to make a new release. Features - you can:

    • make it behave just like 0.12 with argument "s" to import: perl -d:Trace=s scriptfile
    • limit trace to namespaces: perl -d:Trace=Foo::Bar,Baz,Quux scriptfile
      You have to add "main" also to trace scriptfile
    • limit trace to subroutines: perl -d:Trace=Foo=sub1:someothersub scriptfile
    • limit trace by line numbers and number ranges: perl -d:Trace=20-42:123..321,Foo=17-21
      This limits trace in "main" to lines 20 through 42 and 123 through 321 (you may use "-" and ".." for ranges) and to lines 17 through 21 in package Foo
    • trace the codepath stemming from limited traced lines: perl -d:Trace=20..42+:123-321
      Lines 123 - 321 are traced in main but not calls, whereas the entire codepath in lines 20 - 42 is followed
    • exclude packages from trace in the open codepath: perl -d:Trace=42-127+:somesub,Net::LDAP=0
      Codepath in lines 42 - 127 is followed as well as calls to "somesub" in main, excluding code in Net::LDAP
    • provide other filehandles to trace to (which comprises tracing to a variable) by assigning an open filehandle to Devel::Trace::FH
    • provide an alternative format for trace output by assinging a sprintf format to Devel::Trace::FORMAT
    • use a formatting function by assigning a function reference to Devel::Trace::FORMAT
      An ugly example is shown below

    Now it is possible to narrow down tracing to just the interesting parts of a program without touching the source. It is not fully tested and possibly has bugs. I'd be happy if you'd like to play with it and comment. Bug reports, critics, suggestions for improvement, code review etc are most welcome. Have fun!

    update:
    - changed the "simple" handling
    - removed useless code from yDebug.pm

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Challenge: Ricochet Robots
6 direct replies — Read more / Contribute
by LanX
on Feb 18, 2021 at 11:16
    Ricochet Robots is a board game about optimizing moves. (see wikipedia description)

    The 4 pieces represent the "robots" Blue, Yellow, Red and Green on a board with 16x16 cells and some walls.

    Rules: Each round one of the robots can be moved horizontally or vertically, and does not stop until it reaches an obstacle - either a wall or another robot.

    E.G. in this example the Yellow on B14 can only reach A14 or B16 in one move, and nothing in between. You can only move one robot per round.

    The object of the game is to bring one specific robot to an indicated target (here C9 marked with * ) using as few moves as possible.

    (Since the goal has no neighboring wall you'll need to position other robots as obstacles nearby to reach it)

    A B C D E F G H I J K L M N O P --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 1| | R | |1 . .---. . . . . . . . . . . .---. . 2| | | |2 . . . . . . . . . . . . . . . . 3| | |3 . . . . . . . . . . .---. . . . . 4| | |4 . . . . . .---. . . . . . . . .---. 5| |5 ---. . . .---. . . . . . . . . . . . 6| | |6 . . . . . . . . . . . . . . . . 7| | | |7 .---. . . . . .---.---. .---. . .---. . . 8| | | | |8 . . . . . . . . . . . . . . . . 9| * | | |9 . . . . . . .---.---. . . .---. . . . 10| | B | |10 . . . .---. .---. . . . . . . . .---. 11| | |11 ---. . . . . . . . . . . . . . . . 12| |12 . . . . . . .---. .---. . . . . . . 13| | | |13 .---. . . . . . . . . . . . . . . 14| (Y)| | |14 . . . . . . . . . . . . . .---. . 15| | | |15 . . .---. . . . . . . .---. . . . . 16| | G | |16 --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- A B C D E F G H I J K L M N O P

    Question:
    • Whats the shortest solution (in number of rounds) to bring Yellow on target? Please display the moves for each round at the end.
    Provide a runnable Perl script solving it in under 15 min on a current home PC.

    Bonus question:

    If you are still bored...

    • How many rounds do you need at most to reach any field?
    • How many rounds to you need if the goal has to be reached by any of the robots, like the Blue?
    Careful

    I do have a script I wrote 16 years ago.

    It needed over an hour back than and runs today in 1:30 min on my laptop, so it's solvable within the given margin. :)

    But it took me two days to write it, and you might run into memory problems.

    FUN

    I had a lot back then, and learned a lot. Hope you too ... :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    Edits

    added some clarifications and links

    UPDATE

    here the positions of the walls (yes strings as non-strict barewords, this script is old)

    @vwalls=(A5,A11,B7,B13,C1,D15,E5,E10,G4,G10,H7,H9,H12,I7,I9,J12,K7,L3, +L15,M9,N7,O1,O14,P4,P10); # below cell @hwalls=(B2,B7,B14,D10,D15,E1,E6,E16,F4,F11,G8,G9,H13,I8,I9,I13,J1,K3, +K8,L15,M10,N2,N7,N14,N16); # to the right $Target="C9"; $Y="B14"; $R="J1"; $G="F16"; $B="M10";

    UPDATE

    It's specifically requested to bring Yellow on target, the first version was misleading, sorry.

  • removed (updated) marker in title again, to avoid "inheritance" to replies
[OT] Brendan Eich interview
1 direct reply — Read more / Contribute
by tangent
on Feb 15, 2021 at 18:07
    I found this interview very interesting - Brendan Eich: JavaScript, Firefox, Mozilla, and Brave | Lex Fridman Podcast. It is 3 hours long but the time just flew by. An insider's view on the whole history of web technologies, with a little bit of politics thrown in every now and then.

    https://www.youtube.com/watch?v=krB0enBeSiE

Brute force vs algorithm (PWC # 100)
8 direct replies — Read more / Contribute
by 1nickt
on Feb 15, 2021 at 13:06

    Hello beloved brethren,

    I don't usually participate in the Perl Weekly Challenge but for the occasion of the 100th challenge I thought I'd give it a try.

    The challenge

    You are given triangle array. Write a script to find the minimum path sum from top to bottom.

    When you are on index i on the current row then you may move to either index i or index i + 1 on the next row. Example:

    Input: Triangle = [ [1], [2,4], [6,4,9], [5,1,7,2] ] Output: 8 Explanation: The given triangle 1 2 4 6 4 9 5 1 7 2 The minimum path sum from top to bottom: 1 + 2 + 4 + 1 = 8 [1] [2] 4 6 [4] 9 5 [1] 7 2

    Solutions?

    More complex than it first seems, this task requires the programmer to look ahead further than the "next move" to see which "move" is correct. I think the solution involves some sort of recursive algorithm but I cannot see how one could avoid computing all possible paths. It's not possible to assume that the lower of the two choices for "next move" is the correct move, as it may lead to a subsequent choice of two very high numbers.

    I eagerly await minds brighter than mine to provide "correct" ways of doing this. In the meantime here's my brute-force approach which works well, given that the spec is for a four-row triangle:

    # PWC 100 use strict; use warnings; use feature 'say'; use JSON::PP; use Test::More; while ( my $line = <DATA> ) { my ($json, $expected) = split /\s/, $line; my $aoa = decode_json($json); is( compute($aoa), $expected ); } sub compute { my @aoa = @{shift()}; my $total; for my $r1_ix (0,1) { # second row for my $r2_ix ($r1_ix, $r1_ix+1) { # third row for my $r3_ix ($r2_ix, $r2_ix+1) { # fourth row my $sum = $aoa[0][0] + $aoa[1][$r1_ix] + $aoa[2][$r2_ix] + $aoa[3][$r3_ix]; say sprintf('Sum of %d (%d, %d, %d, %d)', $sum, $aoa[0][0], $aoa[1][$r1_ix], $aoa[2] +[$r2_ix], $aoa[3][$r3_ix]); $total = $sum if ! $total || $total > $sum; } } } return $total; } done_testing; __DATA__ [[1],[2,4],[6,4,9],[5,1,7,2]] 8 [[9],[1,6],[7,8,2],[5,8,2,3]] 19

    Here's to a lively discussion!


    The way forward always starts with a minimal test.
Using MinGW to build perl on windows forcing it to expand * into glob in cmd.exe
3 direct replies — Read more / Contribute
by Discipulus
on Feb 14, 2021 at 11:01
    Hello folks,

    -Introduction-

    A recent post evidentiated a bug in some raku builds for windows: if compiled using MinGW (instead of compiled with MS tools as rakubrew uses) an unexpected expansion of * into a glob happens in cmd.exe prompt. The thread born because Athanasius found impossible to escape this * in cmd.exe (more on this later on).

    Contributions to the above threads highlighted a fact unkonwn to me: there is a tiny layer, the C runtime library, responsible to find argc and build argv to pass to main (see jcb's answer). The actual C runtime library depends on the tool used to build perl (or raku). At least this is what I understood.

    While the above is interesting per se triggered another question in my mind: if a raku built using MinGW unintentionally expands * there must be a way to build a perl that expands too * into a glob. You will see later on why this is a futile question, but: futile, complex and hackish is exactly the kind of task I love.

    -Prepare the ground-

    To build this new frankestein perl we need: a recent strawberry portable edition: strawberry-perl-5.32.1.1-64bit-portable is what I used. Extract this wherever you want: in the following examples I will use C:\ulisse\perl5.32-64bit

    Then we need to download perl-5.32.1.tar.gz.

    Finally make an empty dir to use as playground. Open the folder where you extracted the strawberry portable edition and launch the portableshell.bat then in the prompt window execute (adjust to your needs):

    ---------------------------------------------- Welcome to Strawberry Perl Portable Edition! * URL - http://www.strawberryperl.com/ * see README.TXT for more info ---------------------------------------------- Perl executable: C:\ulisse\perl5.32-64bit\perl\bin\perl.exe Perl version : 5.32.1 / MSWin32-x64-multi-thread C:\ulisse\perl5.32-64bit>x: X:\>mkdir globperl X:\>cd globperl X:\globperl>

    Then just to be sure nothing in PATH will interfere with our experiments clean up the PATH as much as possible, leaving only strawberry directories and windows system ones (adjust to your needs):

    X:\globperl>set PATH=C:\ulisse\perl5.32-64bit\perl\site\bin;C:\ulisse\ +perl5.32-64bit\perl\bin;C:\ulisse\perl5.32-64bit\c\bin;C:\Windows\sys +tem32;C:\Windows;

    Finally extract the source of perl downloaded from CPAN, perl-5.32.1.tar.gz to X:\globperl\perl-5.32.1

    -Modify the source code-

    Browse the folder X:\globperl\perl-5.32.1\win32 and edit the win32.c file, in my case around line 73 and change:

    #ifdef __GNUC__ /* Mingw32 defaults to globing command line * So we turn it off like this: */ int _CRT_glob = 0; #endif

    the relevant line into int _CRT_glob = 1; save and close the file.

    In the same folder edit the runperl.c file around line 19 in my case putting again int _CRT_glob = 1; and so resulting in:

    #ifndef PERLDLL int _CRT_glob = 1; #endif

    Save and close.

    -Compile it-

    In the above portableshell.bat window move to the cd X:\globperl\perl-5.32.1\win32 directory where win32 perl source is. Now we have to instruct gmake ( which will use GNUmakefile inside win32 folder while Makefile and makefile.mk are used by other flavours of make) to install our new perl inside a custom dir. We can modify the GNUmakefile (around lines 49 and 50) to use different INST_DRV and INST_TOP or we can feed this parameter from command line.

    So we are ready to build and install our new perl:

    X:\globperl\perl-5.32.1\win32> gmake INST_DRV=x: INST_TOP=X:\globperl\ +my_perl # CCTYPE=GCC # GCCBIN=gcc # GCCVER=8.3.0 # GCCTARGET=x86_64-w64-mingw32 # GCCCROSS= # WIN64=define # ARCHITECTURE=x64 # ARCHNAME=MSWin32-x64-multi-thread # MAKE=gmake [...] X:\globperl\perl-5.32.1\win32> gmake install [...]

    -First test and dll hell-

    This shouldnt happen but as happened to me can also happens to you. Open a new command prompt ( not a portableshell.bat but a regular plain cmd.exe prompt). I erase completely PATH to be sure nothing will interefere, then I tried to invoke our brand new perl

    C:\Users\io>set PATH= C:\Users\io>x:\globperl\my_perl\bin\perl.exe -v

    A nasty error window pops up complaining libgcc_s_seh-1.dll is missing. It is present in the C:\ulisse\perl5.32-64bit\perl\bin strawberry folder and should be available during building, but we can copy in our brand new perl\bin directory to overcome the error, but then another error pops up about missing libwinpthread-1.dll and then again about libstdc++-6.dll so we copy these missing dlls and finally we got a sane perl.exe

    C:\Users\io>copy c:\ulisse\perl5.32-64bit\perl\bin\libgcc_s_seh-1.dll +x:\globperl\my_perl\bin 1 file copied. C:\Users\io>copy c:\ulisse\perl5.32-64bit\perl\bin\libwinpthread-1.dll + x:\globperl\my_perl\bin 1 file copied. C:\Users\io>copy "c:\ulisse\perl5.32-64bit\perl\bin\libstdc++-6.dll" x +:\globperl\my_perl\bin 1 file copied. C:\Users\io>x:\globperl\my_perl\bin\perl.exe -v This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x +64-multi-thread Copyright 1987-2021, Larry Wall

    Hurrah!!

    Sometimes the dll hell can be even worst and the sybilline The application was unable to start ... 0x000007b error appears: in this case you can profit of the wonderful program Dependencies to dipanate the dll hell.

    -Fire proof-

    Now let's look if our new perl is able to expand * into glob on cmd.exe as we wanted to prove:

    X:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" * corelist.bat cpan.bat enc2xs.bat encguess.bat h2ph.bat h2xs.bat instmo +dsh.bat json_pp.bat libgcc_s_seh-1.dll libnetcfg.b at libstdc++-6.dll libwinpthread-1.dll perl.exe perl5.32.1.exe perl532 +.dll perlbug.bat perldoc.bat perlivp.bat perlthank s.bat piconv.bat pl2pm.bat pod2html.bat pod2man.bat pod2text.bat pod2u +sage.bat podchecker.bat prove.bat ptar.bat ptardif f.bat ptargrep.bat shasum.bat splain.bat xsubpp.bat zipdetails.bat

    Tadàaaa! :)

    -Why not?-

    Now we have a perl expanding * into a glob, but... what if we need to pass a regex? Oh well we can escape an eventual * you'd say. No: this * is impossible to escape!

    cd x:\globperl x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" * my_perl perl-5.32.1 x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" "*" my_perl perl-5.32.1 x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" ^* my_perl perl-5.32.1 x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" '*' '*' x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" "^*" ^* # this is really fun! It globs the root of the current drive x: # Infact in windows each drive letter has its own root: \ x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" \* \$RECYCLE.BIN \globperl x:\globperl\my_perl\bin\perl -e "print join ' ', @ARGV" \\* \\*

    No way. It is because of this that Athanasius spotted a bug in the above mentioned post

    -Acknowledgements and useful reads-

    Thanks to Athanasius, jcb and sortiz (who supported me also in the #raku irc channel) for their contributions to the raku post.

    I got an invaluable and patient help from a wise one in the #perl freenode irc channel who pointed me to the relevant source code modifications needed and helped me to escape from dll hell.

    They also explained me that glob expansion is disabled by default because MinGW used to enable it by default, but now while mingw-w64 crt defaults to disabled globbing, mingw-builds scripts, which is what most people use to build mingw, instead of doing that manually, do enable glob expansion by default.

    There are other discrepancies: while in mingw-w64 _CRT_glob is a boolean in mingw.org it's a bitfield.. so good luck.

    See mingw-w64-headers/crt/_mingw.h.in and confront with _mingw.h.in (search for: "* Manifest definitions for flags to control globbing of the command line").

    Also an interesting page about escaping in cmd.exe and a SO answer and dont miss everyone-quotes-command-line-arguments-the-wrong-way ( the last one added 2021-02-15, found here)

    Nice, no?

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Renaming all files in a directory
5 direct replies — Read more / Contribute
by Aldebaran
on Feb 01, 2021 at 22:17

    I'm so relieved to be back at my keyboard, with a roof over my head, fridge full of food, and plentiful water of varied temperature. I was feeling kind of stuck because I had a repository that I had downloaded that didn't have the proper credentials, and it was preventing updating. I got that all cleared away, so now I have:

    $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.2 LTS Release: 20.04 Codename: focal $

    One of the first things I'll do is create a webpage describing the trip, and that is going to require that a bunch of odd images gets herded to the net, with an exact number of corresponding captions. For this task, I find that I can really economize on GUI events with perl and a little skill on the command line.

    But I'm one of those guys who would make every mistake in the book if I started at square one. I know that I had a thread some time back called renaming all files in a directory. I tried to search for this with keywords but had to resort to scrolling through my writeups back to 2012. I was gonna complain that the search didn't work. However, I had searched for the word 'rename' not 'renaming', and I realize that the problem is not with the software.

    I tried one of the answers I hadn't used before:

    ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter"." +.jpg"; +rename($old,$new);$counter++;' $

    That command didn't work at first, but I could get my way to one that did because what exists between single quotations is lexical perl that I understand. And gosh, I've been pretty diligent about studying this including taking in Util's talk at 2020 perl conference, which helped me understand how people "get there on the command line."

    $ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter". +"jpg"; > +rename($old,$new);$counter++;' $ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter". +".jpg"; +rename($old,$new);$counter++;' $

    and voila...

    $ pwd /home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/aimages $ ls image0.jpg image12.jpg image15.jpg image3.jpg image6.jpg image9. +jpg image10.jpg image13.jpg image1.jpg image4.jpg image7.jpg image11.jpg image14.jpg image2.jpg image5.jpg image8.jpg $

    Another modification gets my captions looking all uniform, so I know I've got a bijection going:

    ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="caption"."$counter". +".txt"; +rename($old,$new);$counter++;'
    $ pwd /home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/captions $ ls caption0.txt caption13.txt caption2.txt caption6.txt caption10.txt caption14.txt caption3.txt caption7.txt caption11.txt caption15.txt caption4.txt caption8.txt caption12.txt caption1.txt caption5.txt caption9.txt $

    Now I know that my data will be well-conditioned for use by other scripts to get it onto the net.

    This was just my day in having perl making something easier....


Add your Meditation
Title:
Meditation:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.