4 ms·
About 5-6 years ago I found a new niche for Perl in my day-to-day work. I did a lot of shell scripting at the time and was constantly getting annoyed by subtle
by andrewl-hn 3y ago
About 5-6 years ago I found a new niche for Perl in my day-to-day work. I did a lot of shell scripting at the time and was constantly getting annoyed by subtle differences between macOS and Linux. Sed is especially difficult, because the flags in BSD version and GNU version for in-place search and replace do not match. Plus, sed regexes are more primitive compared to most other languages.
I decided to switch from sed to Perl for all my string replacements and at the time it made my life so much easier! Eventually I started expanding my Perl use to a few lines of code at the time, and now I write a few larger (100+ LOC) scripts in it a year.
Funny how my personal journey matches the story of Perl back in the 80s: it was born to replace more primitive tools.
- silisili 3y agoFor anyone who cares, sed -i'' should be compatible on both mac and linux.
- naniwaduni 3y agoIt is not. -i'' is exactly the same thing as "-i", and while GNU sed interprets this as an empty suffix, BSD sed expects -i to take an argument normally, and will treat the next argument as the extension. If you instead use sed -i "", as is appropriate with a BSD sed, GNU sed will interpret that as the empty program and try to read from a file named your actual script.
- LegibleCrimson 3y agoI hate that behavior of GNU sed (and also of mktemp). Having a flag optionally take an argument is just so weird and surprising, and the syntax is always unexpected and inconsistent.
- jppittma 3y agoI don't see it as a flag that optionally takes an argument, but rather a flag that makes an optional argument mandatory.
- LegibleCrimson 3y agoNo, that's how optional flags should work. I mean how specifically -i works. With GNU sed: -lN, --line-length=N, -l N, --line-length N All work the same, set line length to N. -iSUFFIX --in-place=SUFFIX, -i NEXTARG --in-place NEXTARG Don't all work the same. The argument is only actually taken if it's attached to the flag directly. In the latter two forms, no backup is made. GNU mktemp is similarly annoying, but different, with the --tmpdir flag. -pDIR, --tmpdir=DIR, -p DIR, --tmpdir NEXTARG Only the last one is different. If you use --tmpdir literally without attaching an argument to it, it defaults to $TMPDIR, otherwise it takes in DIR. This is inconsistent and unpredictable. A flag should either take an argument or not. I also dislike Python's argparse variable-length nargs behavior for similar reasons. Even with an integer nargs, it makes for an ugly command line, but with variable-length ones it just gets hideous, and can make it impossible to pass an argument beginning with a hyphen to a flag.
- fouc 3y agoI install gnutils in mac, gsed on mac is compatible with sed on linux.
- Twirrim 3y agoIf you ever use "grep" on mac, it's also worth installing gnutils and switching to ggrep instead as it is significantly faster.
- BrandoElFollito 3y ago> Eventually I started expanding my Perl use to a few lines of code at the time, and now I write a few larger (100+ LOC) scripts in it a year. This was the same road I took in the late 90's - started with simple scripts and ended up with more and more complex scripts when I was learning all the shortcuts. Until the day I could not understand anymore my own code from a few days back :)
- diarrhea 3y agoI wonder, is Perl more ubiquitous than Python for these cases?
- cpach 3y agoPossibly more terse.
- webstrand 3y agoPerl gets installed wherever `git` CLI is available, generally. I'd say it's more ubiquitous. And it doesn't suffer from the python2/3 split.
- librasteve 3y agonot to mention the perl5 / perl6 split perl6 is now called raku
- kstrauser 3y agoNeither does Python, for years now.
- doubled112 3y agoI'm pretty sure people are going to be haunted by it for years. I just updated some internal scripts for Python 3 this year. I believe they should have been Py3 when they wrote them. It was not my decision, but it did become my problem.
- bla3 3y agoThat split was terrible and it took over a decade to fully resolve, but it's behind us now.
- thyrsus 3y ago...for those lucky enough to be able to do so. I've been promised the Red Hat Enterprise Linux 3 systems will be replaced in two years. 10 years ago, they were to be replaced in one year.
- rasz 3y agoNot to mention Write-Only nature of Perl is a nice added job security.
- wdr1 3y agoThis is grossly exaggerated. Yes, sometimes Perl looks like line noise to the uninitiated, but to the seasoned Perl programmer, it looks like checksummed line noise.
- galdosdi 3y agoI picked up the same habit years ago in my first job because we worked with a mix of all the UNIXes (AIX, HPUX, Solaris, etc). Always "perl -pe" instead of "sed" and man oh man you're right perl is amazing for that, its original task The trend then was towards standardization towards linux, but then that got compromised as that's when macbooks got popular with developers.
- ydant 3y agoPerl was my first programming language love. While we've largely gone our separate ways, we still keep in touch and occasionally we still spend some time together. One such case is adhoc small scripts mid pipeline. There's just certain Perl syntax that's so deeply embedded in me that no matter how much I try to learn sed/awk/tr, I can't help but reach out to my old love in times of weakness and need. I just know how to talk to Perl in the most intimate of ways that's been hard to reproduce in other languages. I still feel a little like I've betrayed Perl a bit every time I use Python. Perl, Larry Wall, Randal Schwartz, Tom Christiansen, brian d foy, O'Reilly, and the many other participants of comp.lang.perl.* had such a lasting influence on my programming career. I wouldn't be who I am today as a programmer without having experienced all the Perl community put out into the world.