Hi, Sami! Please reply to all recipients.
On Fri, 24 Mar 2017 00:17:33 -0700 Sami Joseph <sami.jos...@gmail.com> wrote: > Hi, > > I am interested to understand what this guy did, but i am unable to, can > someone please break it down to a newbie > > I've spent the last several days at work, trying to "take over" some work > left behind by a departing colleague. I realized we didn't have some of his > bash scripting in ansible or in a repo, so I decided this would be a good > opportunity to fix all of those problems. After a little while it became > clear his script was a set of functions, run in a loop-within-a-loop to > iterate through a bunch of things. In the middle, between these two loops, > is a pile of inline *PERL* that runs as a bash function and passes data See http://perl-begin.org/learn/Perl-perl-but-not-PERL/ - it should not be capitalised as "PERL". > back and forth in all directions. This Perl generates some dynamic SQL > commands each loop. > > I hate SQL. > > Okay... read the Perl. Now, it's been a long time and a long way since my > last string of PERLs, so i didn't really grok 100% what I was reading, but > I got the gist of it. Finally figured out the SQL wasn't the problem. > > Another day goes by, and I finally figure out his code is self documenting! > That was what all the little bits were in the perl I didnt get. PerlPod. So > now I can figure this out easy . Run it, read the code, make a change, run > it... *boom* what? > > Nope. > > It took me several more hours and a few beer, and it finally clicked. He > was using PerlPod to document out the code he didn't want to run, and > commented out the documenting code to run the code he wanted. What looked > commented out, wasn't, and what looked like a pile of variables being set, > was just a bunch of commentary. He was using a documentation module for > *flow control*. today I learned that it can be spelled as "Perl Pod" - http://perldoc.perl.org/perlpod.html - I thought "POD" was the correct spelling. Anyway, you are right that it can be used for excluding code from being compiled. The common idiom is: =begin removed . . . =end removed =cut Anyway, using Pod for Perl code embedded in bash or other shells is really "What-the-f****??"-y. One should avoid embedding such long code (beyond a short -e or -E string) in bash at all, and keep the code in a separate program file (also see the Modulino concept - http://perltricks.com/article/107/2014/8/7/Rescue-legacy-code-with-modulinos/ and https://www.masteringperl.org/category/chapters/modulinos/ ). Regards, Shlomi Fish > > What a Hacker. Holy shit. Blew. My. Mind. > > I just got schooled very seriously. It's nice to know I can still improve > *that much*, even from where I am. > > > When PerlPod is used to document something, anything between control codes > is not interpreted but treated as commented text. He would comment out the > control codes (thus rendering the text interpretable) on the parts meant to > run, which would differ between machines. -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ http://youtu.be/xZLwtc9x4yA - Anime in Real Life!! (Parody) We don’t know his cellphone number, and even if we did, we would tell you that we didn’t know it. — http://www.shlomifish.org/humour.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/