DC.pm Attendees
Notes from the Conference
(Added by Lisa W. Please feel free to edit, especially if I got anything wrong.)
CPAN Modules and Other Cool Things to know about and possibly use (in no particular order)
- Moose: a CPAN module that enables object oriented programming in Perl.
- HTTP::Engine as an alternative to CGI.pm
- CGI::Test to test web forms.
- Also WWW::Mechanize and WWW::Selenium for web form testing.
- Rx: Regex Debugger Module.
- Data::Dumper: Let's you see the contents of references to structures, objects, etc.
- Tag URI: Algorithm to create a unique URI.
- RELAX NG: Let's you write XML schemas more easily.
- KiokuDB: Store any object structure in memory forever and requires very little code. Uses ids to retrieve the objects. No need for a database schema. Can also make your processes more efficient.
- JSORB: Communicates between javascript and perl code. Makes it easy to add Ajax functionality.
- NYTProf: Perl Profiler.
- AnyEvent::DBI: Allows you to run DBI events in parallel to performing other tasks.
- Net::Google::Code: Library for projects hosted in Google Code.
Memory Management with Perl
- Use Devel:: Peek and Devel::Size to look at the memory footprint of a variable
- The way to get memory back is to assign it to a new scalar variable.
- Chomp lines before pushing them onto an array.
- Pushing $_ onto a list recycles the original variable.
- Pushing “$_” onto an array pushes a copy onto it.
- Strings don’t shrink
- Use lexical variables to return memory
- Clean variables up before assigning them
- Arrays are reduced by adding a skip count to the array and reducing the length. This can lead to all sorts of confusion if you try to free up space by shifting data off an array.
- What does shift not do? It does not change the allocation of the structure, just the visible portion. Same with pop.
- If you do a push followed by a shift, your array will be smaller.
- Lexicals return their scope.
- Arrays really don’t shrink either. You can recover space from values stored in an array, but the SA structure only grows.
- Clean up the array and then assign it to a new variable.
- Hashes are bigger than arrays. Arrays are more efficient than hashes.
- Deleting keys from the hash does not reduce the structure.
- Even assigning @a = 0 does not reduce the buffer.
- Clean up (chomp, etc) the $_ before pushing it onto the array.
- Generate structures before you fork.
Regexp Mini Tutorial:
- Backreference - \1, refers to first set of parenthesis.
- A bunch of the things mentioned in the list below are available In 5.10:
- \g{1} – also refers to the first set of parenthesis.
- \g{-1} – matches the previous set of parenthesis.
- (?| ) – Inside this, each | resets the counter.
- You can also name your capture: (?<name>pattern)
- Or (?’name’pattern)
- And you refer to them using \g{name}
- %+ holds the leftmost successful captures, indexed by name.
- %- holds all successful captures, indexed by name (??)
- @- and @+ store offsets in the string matched against.
- For example, $- [1] and $+ [1] are the offsets of the first capture.
- There’s no way to currently do this with a named capture though.
- /p modifier – if /p is present, Perl will set ${^PREMATCH}, ${^MATCH}, and ${^POSTMATCH}
- (?1) – recursive, refers back to a sub pattern.
- Pattern recursion treats the contents of a particular pattern buffer as an independent sub expression.
- (?1) recurses to the first pattern buffer, (?2) refers to the second, etc.
Fundamentals of Modern Perl
- Perl 5 will exist for a long time after the stable release of perl 6
- Huge legacy code problem. There’s a lot of horrible code online, available as freebies and tutorials.
- Perl 5 is not year 2038 compliant. Use Time::y2038. Also use 64 bit version of Perl.
- Use CLASS->method to pretty up your code.
- Check out autobox. Allows you to call methods on anything.
- Check out Perl5i
- Learn Moose to create object systems instead of non-object functionality of references.
- Use roles with Moose. Google “the-why-of-perl-roles”.
- Never use ExtUtils::MakeMaker
- Autodie instead of “|| die”
- Perl::Critic : lets you customize what your project will allow and disallow.
- http://www.modernperlbooks.com
- difference between autodie and fatal: autodie works.
XML::Toolkit – Tools to ease the pain
- SAX – lets you streamline the event processing on your XML documents. Can turn the events into Moose objects. XML::Toolkit also tidys, so only the whitespace will be different (tidier).
- Drawbacks – only one child, needs to work on less complex XML
- Check out NYTProf.
Warming up to Modular testing with Test::Class
- Arcos::Test convenience methods. Includes LWP::UserAgent to check the server response.
- Test::Builder – error message coming from the line where it was called, not from the sub routine.
Mojo Mojo Catalyst Powered Wiki:
- Can put a topic where ever you want, then add tags to categorize (similar to Flickr).
- Very nice side by side wysiwyg tool and preview page.
- Very easy way of adding tags
Test::Regexp
- Regular expressions don’t necessarily work the way that you expect them to on special language characters. (Specifically unicode or for specific font sets that are not in your locale charset.)
- New cpan module to easily test whether or not the pattern really matches the string that you are looking for.
- Also look into TAP and Test::Builder.
TAP In Depth:
- “Testing Anything Protocol”
- Also check out Test::More, Test::Most, Test::Class
- TAP modules also exist for other languages, such as Python, PHP and JavaScript