DaWolf has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow monks.
I've been away from Perl for almost 3 decades and I have a technichal interview coming for a Perl position.
While I've already did some coding and coming back to write Perl feels comfortable, I wonder if you could enlighten me with some relevant issues for the Perl marketplace nowadays, and of course, provide some links.
Here's a few I've came up with but please feel free to add your own:
- Frameworks for web development: what are the most popular ones?
- Changes to the language itself
- OO Perl?
I'd really appreciate your help on getting back to a language that I've always loved.
TIA,
Re: Returning to Perl after almost 3 decades
by talexb (Chancellor) on Aug 15, 2024 at 02:26 UTC
|
Well, for a language that everyone keeps saying is dead, there's been a lot of progress in 30 years. :D
For your questions,
- Frameworks: there's Dancer2 and Mojolicious for web apps. I used CGI::Application probably 20 years ago, but it's been a while. And I still use Template::Toolkit for web pages -- see also their website. So handy.
- Changes to the language itself: Well, there are lots, I guess. if I try to list all of them, there will be lots of posts adding, "Hey you forgot this other important thing" ..
- You can use // as an or in an assignment, so you can write code like my $result = $this // $that // $the_other_thing;.
- The default include search path @INC no longer includes the current directory ('.');
- creating an object is done using my $cgi = CGI->new; now, and not my $cgi = new CGI;
You should probably go read some of the perldeltas and get a better handle. Those are just the first few things that came to mind.
- OO Perl: There's a new object model being added to Perl called Cor, and again, you should go read perldelta and maybe watch Ovid's presentations about this topic. The original way of creating objects is still around, as follows:
sub new
{
my ( $class, $args ) = @_;
my $self = {
width => $args->{width} // DEFAULT_WIDTH,
};
bless $self, $class;
}
Welcome back!
Alex / talexb / Toronto
Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.
| [reply] [d/l] [select] |
|
| [reply] |
|
Thank you so much, this is already very helpful.
| [reply] |
Re: Returning to Perl after almost 3 decades
by NERDVANA (Priest) on Aug 15, 2024 at 04:25 UTC
|
I'd say the two biggest developments in the language are named parameters on subs, and native try/catch. Or, perhaps, those were the two most deficient absent features in early perl which perl now has. Perl gives you access to the new features various ways, but the best is use v5.40; which gives you a feature-bundle of everything considered stable and not-deprecated as of version 5.40. This includes strict and warnings, so less boilerplate at the top of your scripts.
use v5.40; # strict, warnings, many features
use Moo; # lightweight object system
use Log::Any '$log'; # my favorite logging system
has field1 => ( is => 'rw', required => 1 );
sub method1($self, $z=undef) {
try {
$self->field1($z) if defined $z;
$self->field2($z // 5);
}
catch ($e) {
say $e;
$log->error($e);
}
}
I don't mean to speak ill of the new in-core object system, but if you give it a try you can decide for yourself whether it meets your needs better than Moo.
Oh, and one of my favorites are indented here-docs:
sub foo {
my $x= <<~END
<-This is the start of the line
END
}
And for a brief overview of the CPAN landscape,
- DBI is still the standard for interfacing with databases
- DBIx::Class is still the best way to automate queries
- Template::Toolkit is going strong, but Text::Xslate is I think the current fastest template system
- There are four major IO loops for event-driven programming: POE (old, complicated), AnyEvent (best for minimalism, but has social baggage), IO::Async, and Mojo::IOLoop (part of Mojolicious, and my favorite). This fragmentation of the module landscape is unfortunate, but then, you can do almost everything you want with a normal blocking-style worker pool.
- Mojolicious is the only web framework that fully supports asynchronous requests, especially for websockets. It comes with its own massive kitchen-sink collection of libraries, but they're all well-written and efficient/minimalist.
- Plack / PSGI make a nice system for plugging together web-app middleware, but they don't support websockets very well.
- Catalyst is still alive and well, but honestly it's more complicated than Dancer and Mojo
- Of the object systems, you have Moo, Mouse, Moose, Zydeco, the new "Cor" being built into the language, and various others. Moo is still my favorite for pragmatism. Mouse is faster, Moose is more "meta", Zydeco looks better and removes boilerplate for common stuff, and Cor will soon be built-in, though it lacks features I consider important.
- Data::Printer is an amazing dumper of perl structures for debugging.
- Carp::Always shows you stack traces
- Log::Any or Log::Contextual are my recommendations for logging. There are many others.
- Type::Tiny is a great ecosystem for validating data. I recommend test coverage instead of enforcing types at runtime, but Type::Tiny certainly has its uses in input validation.
- Test2 is a core module now! It's an excellent domain-specific language for writing tests.
- Cpanel::JSON::XS is the current recommendation for working with JSON
- DateTime is still the best date module, but Time::Piece is lighter weight. My favorite parser is DateTime::Format::Flexible.
- Devel::NYTProf is an excellent profiler for detecting performance hotspots
- Email::MIME and Email::Sender module collections are the standard for constructing and sending mail
- Path::Tiny and Path::Class streamline filesystem access, and check out IO::All if you like to live dangerously
Of course, CPAN is almost infinite, but these are just the ones that I use on a regular basis, and some of their competitors that I know other people like. | [reply] [d/l] [select] |
|
Thank you so much for such a comprehensive answer!
| [reply] |
Re: Returning to Perl after almost 3 decades
by hippo (Archbishop) on Aug 15, 2024 at 13:07 UTC
|
Welcome back. I'm surprised that nobody has yet suggested Modern Perl as a great resource for how to do things "these days" in Perl (even if "these days" is now a decade ago). I'd also recommend a quick browse through Task::Kensho for an opinionated but valuable set of go-to modules.
Frameworks for web development: what are the most popular ones?
For "the marketplace" you'll be unlikely to have to look further than Dancer2, Mojolicious and/or Catalyst.
Changes to the language itself
There's been a few syntax tweaks, a few behavioural changes and some importing of features from popular modules into the core. Nothing to get too worked up about, IMHO.
OO Perl?
Again, have a look at Modern Perl for a fair introduction. For "the marketplace" you will want Moose and probably Moo, but there are plenty of others. I'm a minimalist at heart so will happily give a vote to Class::Tiny if that's all you need.
| [reply] |
|
Thank you! Modern Perl is a great resource and a great book to study further.
| [reply] |
Re: Returning to Perl after almost 3 decades
by cavac (Prior) on Aug 15, 2024 at 12:46 UTC
|
| [reply] |
|
Thank you, very insightful. As for database I'm a PostgreSQL fan =)
| [reply] |
Re: Returning to Perl after almost 3 decades
by Discipulus (Canon) on Aug 16, 2024 at 10:17 UTC
|
Wow! welcome back DaWolf,
a return after a big while, this is why perlmonks is so special :)
I was late and you got wonderful replies (among other ones I liked a lot NERDVANA's look about CPAN).
I'd like to add to the list MCE Many-Core Engine for Perl providing parallel processing capabilities by our brother marioroy (..ok.. it is in Task::Kensho under Async Programming but I want to mention it explicitly ;)
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.
| [reply] [d/l] |
|
It's been around less than 30 years, so also check out PDL!
| [reply] |
Re: Returning to Perl after almost 3 decades
by roho (Bishop) on Aug 27, 2024 at 05:11 UTC
|
Even better is the Perl Tk debugger: perl -d:ptkdb mypgm.pl
"It's not how hard you work, it's how much you get done."
| [reply] |
Re: Returning to Perl after almost 3 decades
by sludin (Initiate) on Sep 30, 2024 at 21:24 UTC
|
I have been an on and off Perl programmer for over 30 years (my Learning Perl (4) book is pink), and I came here to ask almost the same question. Thank you to you and to everyone who replied. I would like to add on and see if I can't extract a bit more wisdom from folks. My problem is that though I have been coding Perl for this long, my knowledge ossified about 20 years ago. I think the Conway Perl Best Practices book could be seen as my last big knowledge tuning. I do not say a lot, and when I saw a recent code example with a postfix dereference operator my mind exploded. That is literally what started this knowledge quest. I am about to kick off a new project and I have the luxury of possibly saying use v5.40;, so I'd like to take full advantage of that.
So what is the best way to get up to date with the latest? Mastering Perl will get me to 5.22 it seems (thank you, chromatic), but how to fill the gap from then until now? Reading each version's perldelta? I'll do that if so. I am not looking for replies with additional changes that are not enumerated already above but rather an RTFM with a pointer to a 'manual'. But if there are any editorial comments about what might be 'new' and is already an anti-pattern, I would love to hear it.
Thank you!
| [reply] [d/l] [select] |
Re: Returning to Perl after almost 3 decades
by perlfan (Parson) on Aug 24, 2024 at 01:03 UTC
|
Welcome back! I recommend binging the all the Perl conference and workshop videos online that are heavy on actual Perl examples, there are plenty. For you time efficiency, I would skip anything that talks about Perl 6 or Raku for the sake of time, since you said your interview is coming up. The hard core Damian Conway videos are probably a good investment. Anything related to Moo, Moose, MOP or whatever (unless your potential employer mentioned them) is going to not focus well enough on core Perl syntax to refresh your memory. But if they mentioned them, you should be aware of the difference it creates in the code. The recent class stuff in 5.40 is relevant. Poking around on https://blogs.perl.org (and here!) is probably a good idea.
What's new in Perl 5.40
https://www.youtube.com/@YAPCNA/playlists
https://www.youtube.com/results?search_query=perl+fosdem | [reply] [d/l] |
Re: Returning to Perl after almost 3 decades
by Danny (Chaplain) on Aug 17, 2024 at 02:25 UTC
|
If you are coming back to perl after 30 years, I would not worry about all the new stuff. Just get a basic handle on the language. If you have that you are probably good. If an interviewer asks about some new syntax, just say you don't know. | [reply] |
|
| [reply] |
Re: Returning to Perl after almost 3 decades
by perlboy_emeritus (Scribe) on Aug 26, 2024 at 18:37 UTC
|
Hello fellow Perl hacker,
The Perl debugger is your best friend. With it you can experiment to study and relearn everything you need to know about Perl. Do:
perl -de test
and hack away. Good luck...
| [reply] [d/l] |
|
|