Perl help

Yeah, if I have one argument against Perl for this job, it’s that it’s the most frustrating language to learn from other’s examples, due to the many ways to achieve the same thing through different syntax. It also makes fixing others’ Perl a pain in the ass sometimes (“What the hell does that operator do?”), but that doesn’t really apply here.

I’m not sure it’s overstated. I’ve monkeyed with other people’s Perl CGI code that was from a project created this decade, and written a few projects from scratch in it in that time. PHP, Python and a host of other languages have definitely made it less prevalent in that role, but it’s not dead in CGI, either.

Python and Perl 5 are exactly the same language. They just have some superficial differences in syntax and culture.

ETA: I should take that back. There is one important difference: Perl does lexical closures correctly.

Heh. Now this guy starts by claiming Python is basically Lisp with different syntax :slight_smile:

Everything is Lisp with different syntax, because Lisp is so generalized that it is actually completely useless for accomplishing tasks.

I had to check the time stamp of this thread, as I thought it was a zombie thread from the 90s. What??

I concur with Atom being an excellent choice. I have never used Perl so I decided to have a go with the OP’s “Hello, World” just for kicks. Atom instantly recognized I was writing in Perl and just did all the right things.

I’ve been writing primarily Perl for a living for over 20 years. The language has evolved tremendously, though it’s not as popular as it once was.

I’m pretty sure AutoCAD’s marketshare would disagree with you, were it not too big to notice your existence.

Anyway, this whole thread reminds me of something Zed Shaw once wrote: Early vs Beginning Coders:

Anyway, and he doesn’t mention this in his little essay/rant, his method for teaching beginning coders is to have them literally type exactly what he has in the book into a shell or text editor, and, yes, he tells them which editor to use.

He’s opinionated to the point of being dictatorial, but seeing what the OP was going through in the first page of this thread, I can understand why: Someone who’s never done anything before in a given field has no opinions, because they have no basis for comparison. They need to copy the opinions of others if they want to get anything done, and they can branch out later if they see something which appeals to them after they have enough knowledge to know why it appeals to them.

Obviously there are still developers doing Perl, but I had to switch when most of the jobs were covering legacy systems. How boring.

From *http://www.cgi101.com/book/intro.html*:

*Author’s note, Feb 2017:
When this book was first published, CGI and Perl was one of the few options for adding dynamic content to a website. These days it’s largely been left behind as newer languages have become popular. Learning Perl/CGI probably won’t get you a job, because hardly anyone uses it anymore. But if you’re a tinkerer — a do-it-yourselfer who wants to learn to code and customize your website — this could be for you.

Perl is an incredibly useful language; I think of it as my secret super-power. :wink: It’s awesome for reading, writing, parsing, reformatting, and summarizing text files, databases, log files, raw data… you name it. It’s useful not just for CGI scripts but for any kind of automated scripting or data processing. And it’s available on most every Unix system, from your desktop Mac to high end cloud servers to the tiny Raspberry Pi. There’s also a huge library of free, pre-written modules for Perl, which you can download from CPAN.

Learning CGI/Perl may not get you many points on your resume, but it’s easy to learn, and you may find it a valuable tool to have in your developer’s toolkit.*

As I’ve said previously and in the first thread where the o.p. was originally asking the question, if he were interested in really becoming a programmer, I’d recommend start with Python (or Ruby, although my preference is for Python and it is the language that seems to be more broadly in favor now for web framework application development despite the earlier popularity of Ruby On Rails), but learning to write good Python code means learning the appropriate programming paradigms and how to correctly format and write code. Perl doesn’t really come with any of that overhead, and if it suffers in terms of readability from developer to developer for its lack of standardization in how to write code, it also makes it easy for someone to pick up and use because they can play around with it and figure out what makes sense to them without worrying too much about the “right” way to do things. And it is purpose designed for text munging with regex functionality built right into the core language. For the o.p., who doesn’t really seem that interested in becoming a general programmer but just wants to solve this particular problem of finding a replacement for Easytrieve.

I had a good laugh over the comment that “Python and Perl 5 are exactly the same language,” and even more with “Everything is Lisp with a different syntax”. It’s actually kind of true; once you understand the mindset of a certain type of programming (declarative functional, imperative, object oriented, et cetera) as long as a language supports that learning it is really more like learning a dialect of a new language rather than having to learn an entirely new skillset. Being a programmer isn’t really the same thing as being a computer scientist–the former is learning the practical applications of programming while the latter is studying more theoretical or abstract methods behind the concept of computing–but a good programmer is actually language agnostic in terms of being able to write good code with some understanding of the particulars of the language. Except for Java–I’ll maintain that nobody can write good code in Java because it is purpose-designed to generate algorithmic shit. The JVM was a great idea, but he Java language is crap that takes the worst ideas from C++ and then guts all the functionality.

Stranger

Honestly, a lot of the shit Perl gets comes from the fact it has the really, really good regular expressions, and regular expressions are a really, really good way to parse text once you have some degree of mastery. They’re traditionally very terse and uncommented, even though Perl supports multi-line regular expressions with comments, but to someone who knows how to read them, they can save pages of code every single time they’re used.

Perl is also used to solve gungy problems, problems like parsing undocumented or otherwise unclean file formats, where there is no clean solution, just working solutions, and the most efficient solution is likely one with a lot of regular expressions.

I mentioned in the other thread that Perl regular expressions have been ported to Python and other languages. Presumably this was done because they are awesome, not because they suck. I also independently have it on good authority that the Perl regular expressions library was implemented by computer scientists who knew what they were doing, and uses optimal or efficient algorithms. So Perl may get shit, but not because of regular expressions.

Legacy=anything currently running in production/live :slight_smile:
My brother’s kids are in high school and doing programming etc. I mentioned something about how we just standardized on Python (got rid of Perl, Powershell, old VB stuff, etc. etc.), and their response was “Python’s an ancient language, we don’t want to use anything that old.”

I had a good laugh.

The fact that Perl’s regexp language was used in Python was one reason I was suggesting Python was a better choice. You get the really good bit of Perl, and none of the cruft.

Doing a flexible fast and easy to use regexp is not easy. The first job I had after graduation had me design and write one. Just getting my head around the needed transforms to get to NFA’s, DFA’s (non-deterministic and deterministic finite state automata) took ages, and Aho and Ullman was my constant companion for weeks. Working through the semantics of lazy and eager matching in a manner that is useful is not trivial either, as well as sub-match extraction. Great fun, and left me with a lasting admiration for people like Henry Spencer - who later wrote the regex library as well as the theory guys. This stuff isn’t easy, and my efforts, although going into production in a locally written text editor, was never fully right - for reasons that I only really understand now.

You also get the verbosity of Python and the need to import external libraries and call them like functions versus essentially calling imperative commands in Perl. Perl is not a great choice for many things but its strengths in text munging (not just the regex but how it handles strings in general) is powerful, and you can learn to use that functionality in minutes without spending the time on how to write structured programs and define functions.

Regexs are impressive, and in many ways the are a precursor to more complex lexigraphical parsing of natural language. The more I used regex, the more I thought about how we actually interpret written language and how you can recognize words in context even when they are misspelled or missing letters. I think there are probably some deeper insights to be gained by understanding something like regex, even if it isn’t strictly how the language cortices of the brain work because their is something in the pattern matching that at least looks like cognitive prediction in written language interpretation.

Stranger

Python gets you the part of Perl’s regular expression language which is easy to port to Python. You don’t get the fact you can embed Perl code in Perl regular expressions, which, like so much of Perl, is something you should only use rarely but which can make programs much more expressive in the hands of an expert.

And Perl is an expert’s language, in that it is full of ways to make code adhere to different standards: Shorter, easier to read as English, more functional, more OO, and so on. It leaves the decision of what “better” means to the programmer, much like Common Lisp. Python, on the other hand, follows Scheme in deciding that there is one Pythonic way, and “better”, in Python, necessarily means More Pythonic, more in line with the single style the language tries to enforce in every case.

They’re both useful. They’re both practical. (Well, Python doesn’t have anything like the perl interpreter’s -p and -n command-line options to facilitate one-liners, but Python doesn’t really do one-liners.) They’re both potentially readable or potentially unreadable. They just approach “friendly” from different directions.