The CPAN ecosystem is more than just a way to share your code with other people. It’s also a way to let other people collaborate on the code and to help you release it. In Item 70. Contribute to CPAN, you saw how to upload your work to the Perl Authors Upload Server (PAUSE). There’s a lot more that you can do through PAUSE, though. Even if you aren’t a CPAN author, you can use PAUSE to find out more about a module’s authors and comaintainers. Continue reading “Find a module’s release managers”
Category: chapters
Count the number of times a character occurs in a string
This Item isn’t really about counting characters in a string, but we thought we’d expand on an Item in the original Effective Perl blog that Joseph set up to support the first edition of Effective Perl Programming. He had an Item titled “Counting the Number of Times a Character Occurs in a String”. We won’t reproduce it here, so you should read his version too. Continue reading “Count the number of times a character occurs in a string”
Force install a module to reinstall it
[This is a midweek bonus Item since it is so short]
I recently bought the new MacBook Air, which means my solid state device has over four times the storage as my old MacBook Air. For the first time, I used Apple’s migration tool to transfer everything from the old one to the new one. It even transferred my perl installations, and I thought that would be fine. It mostly is, except for some compiled modules that cause strange, new errors. Programs don’t load correctly, modules don’t compile, and things go horribly wrong when running test suites. Continue reading “Force install a module to reinstall it”
Make your methods know as little as possible
How often have you wished that one of Perl’s modules did things slightly differently? That module mostly works for you except for some hard-coded decisions in string formats, pack specifications, or other minor point that you wish that you could configure. Continue reading “Make your methods know as little as possible”
Make exclusive flip-flop operators
In Respect the global state of the flip flop operator, you saw some examples of the ..
scalar operator. The flip-flop operator returns false until its lefthand side is true. Once the lefthand side is true, the flip-flop operator returns true until its righthand side is true. Once the righthand side is true, the flip flop operator returns false: Continue reading “Make exclusive flip-flop operators”
Use CORE when you need the real thing
Perl’s a dynamic language, which means you get to change the definition of almost anything while the programming is running. You can even change the defintions of Perl’s built-in subroutine. Once you (or the evil doer who wrote the module you need) change the definition, you might want to get back to the original, and Perl provides a way for you to do that. Continue reading “Use CORE when you need the real thing”
Avoid modifying scalars connected to string filehandles
Since Perl 5.8, you can treat a string as a file (Item 54. Open filehandles to and from strings). You can open a filehandle, read from the string, write to the string, and most of the other things that you can do with a file. There are some gotchas though, when you deal with that string as a normal string and a filehandle at the same time. We’ve filed this as RT 78980: Odd behavior when string filehandles and scalar assignment collide. Continue reading “Avoid modifying scalars connected to string filehandles”
Use array references with the array operators
[Update: Perl v5.24 removes this experimental feature]
There’s a significant change in syntax showing up in Perl 5.14. The array operators push, pop, shift, and unshift previously only worked on named arrays or dereferenced references. Now, thanks to David Golden, they’ll work on array references. Not only that, they’ll work on references that you’ve stored in variables or that come as the return values from subroutine calls. This feature will show up in Perl 5.13.7, so you need to compile a development version to try this: Continue reading “Use array references with the array operators”
Compile a development version of perl
Nowadays, perl
development happens at a fast clip. Every month there’s a new development release that gives you a preview of what’s going to show up in the next stable version. This not only gives the perl
developers a chance to test the new perl in the wild, but also for you to try new features so you can get your application in shape for the next stable release of perl
. As The Effective Perl gives you a preview of some of the upcoming features, you’ll need a development version of perl
to try them for yourself. Continue reading “Compile a development version of perl”
Use the return value from srand
[This is another bonus, mid-week item since it’s so short and probably mostly useless as a tweak to what you already do.]
Perl 5.14 changes srand to return the seed that it used to start the pseudorandom number generator that gives you numbers through rand. There are plenty of interwebs that will explain the difference between real randomness and the sort that you get from computers, but for this item, suffice it to say that the numbers you get from perl are completely deterministic. If you start with the same seed, you get the same sequence. Continue reading “Use the return value from srand”