3 ms·
The next time I need awk or sed, whatever I end up writing I’ll submit to chat gpt and ask it to rewrite it in perl so I can compare. I’m curious because so man
by kagevf 3y ago
The next time I need awk or sed, whatever I end up writing I’ll submit to chat gpt and ask it to rewrite it in perl so I can compare. I’m curious because so many people (well, enough people anyway) speak so highly of perl’s text processing capabilities. If it’s such a great tool, then I want to use it too.
Edit: one plus is that perl is as ubiquitous as awk and sed. It was there the whole time and I didn’t even realize it!
- rmilk 3y agoThis sounds interesting! The main reason I moved to perl instead of sed or AWK is for better control. Shell scripts don’t differentiate between variables and data (anyone else still having nightmares from trying to escape quotes and meta chars in a shell?). Perl gives you all the simple features from sed or AWK and adds useful (maintainable) foreach iterators, arrays, hashes, etc. Recommend using Strict mode if you are new to Perl. It gives good guardrails against silly mistakes like not declaring or misspelling a variables, or accessing strings or numbers that aren’t the correct datatype.
- kagevf 3y agoThank you for the tip re: strict! Escaping - that's definitely a sore point. I feel like I get tripped up by embedded double quotes way too often - does perl have a good way to handle them?
- tod222 3y agoFrom 'man perlop': Customary Generic Meaning Interpolates '' q{} Literal no "" qq{} Literal yes -- where {} can be any bracket pair. my $string1 = q<a single quote '>; my $string2 = qq<a double quote ">;
- tod222 3y ago> anyone else still having nightmares from trying to escape quotes and meta chars in a shell? This was a major reason I downloaded Perl 1.0 off Usenet in 1987.[1] [1]https://news.ycombinator.com/item?id=36657782 https://news.ycombinator.com/item?id=36657782