Wouldn’t it be great if you could stop your program right before it died so you could see what’s causing the problem? You could start the Perl debugger and step your way to the problem, or set up some break points, but that’s often too much work. The Carp::REPL module let’s you drop into a debugger just at the point you need. Continue reading “Use Carp::REPL as an interactive Perl shell.”
Use scalar references to pass large data without copying.
References aren’t just for data structures, and many people overlook the benefit of references to simple scalars. With references to arrays and hashes you can keep those data structures in tact when you pass them to or return them from subroutines (Item 46: Pass references instead of copies). You don’t need to worry about scalar values because they are a single item in both the non-reference and reference form. Continue reading “Use scalar references to pass large data without copying.”
Effective Perl Programming looks better than most on the Kindle.
Here are some images from the Kindle version (on an iPad) of Effective Perl Programming. It doesn’t look bad considering how bad most other non-novels look on Kindle, and its readable. These are two non-consecutive pages: Continue reading “Effective Perl Programming looks better than most on the Kindle.”
Effective Perl Programming is now on Kindle.
Effective Perl Programming is now available in a Kindle edition:
Continue reading “Effective Perl Programming is now on Kindle.”
Use each() on an array in Perl 5.12.
Before Perl 5.12, each only took a hash argument. In list context, it returns a two item list of a key-value pair you had not seen yet (unless you changed the hash in some way that re-ordered it): Continue reading “Use each() on an array in Perl 5.12.”
A Chinese translation of Effective Perl Programming is in the works
There’s a Chinese translation of _Effective Perl Programming_ in the works. I don’t know when it will be available: the translation will take some time, then the publisher has to put it on paper, then it has to show up in stores. I don’t have any details on where or how you can buy the translation. If you know those, please let us know and we’ll post the details here (even using your referral link).
However, if you’re reading this directly, the Chinese edition might not matter to you. :)
If you know about any other translations, tell us about those too. Often the author doesn’t find out about them until they get a copy, if they ever get a copy.
Perl 5.12 new features
Perl 5.12.1 is out, which is the sign that it’s time for normal users to pay attention to it: that first point release should have sanded down all the rough edges. As usual, the complete list of major changes is in the perldelta5.12.0 documentation, we’ll cover some more of the interesting features in The Effective Perler in the coming weeks. Our initial list of user-interesting features include: Continue reading “Perl 5.12 new features”
Use B::Deparse to see what perl thinks the code is.
We used B::Deparse in Item 7. Know which values are false and test them accordingly, but we didn’t say much about that module. The B
namespace has many modules that do various nasty black magic things with the perl parse tree. Continue reading “Use B::Deparse to see what perl thinks the code is.”
Compare dates as strings when you can.
Just because you find a module that does something doesn’t mean that you have to use it. There are many excellent date and time modules on CPAN, including most people’s favorite, DateTime. In your heady rush for program purity and elegance, don’t think that you always have to use objects to do your work. Sometimes the overhead of objects, which have to call (perhaps many) subroutines to do their work, is too expensive. Continue reading “Compare dates as strings when you can.”
Effective Perl free sample chapter: Files and Filehandles
Addison-Wesley converted our chapter on “Files and Filehandles” to HTML and put it online for as a free sample chapter. I selected this chapter as the free sample because it was the most fun to write but also the most valuable to new Perl programmers. Filehandles are the way you interact with the world, and using them wisely can give your program quite a bit of flexibility and make many tasks much easier.
Here’s the list of Items from that chapter, each of which you can read for free online:
- Item 51. Don’t ignore the file test operators.
- Item 52. Always use the three-argument open.
- Item 53. Consider different ways of reading from a stream.
- Item 54. Open filehandles to and from strings.
- Item 55. Make flexible output.
- Item 56. Use File::Spec or Path::Class to work with paths
- Item 57. Leave most of the data on disk to save memory.
We’ve also added more Items for “Files and Filehandles” in this blog, which you can also read for free. However, don’t forget about that Donate button on the right had side of the page if you find this site valuable. Or, buy our book and encourage all your friends to buy our book. Donations and book sales give us a little motivational boost to keep going. :)