[pm-h] Good article on split

G. Wade Johnson gwadej at anomaly.org
Mon Oct 27 20:50:48 PDT 2014


David Farrell has released a really good article on Perl's split.

http://perltricks.com/article/121/2014/10/24/Perl-s-versatile-split-function

Unfortunately, he left off one of my favorite features: the third
argument.

   my ($key, $value) = split /:/, $line, 2;

This works much better than something I've seen repeatedly

   my ($key, $value) = split /:/, $line;

when the input line looks like: "plugin:Module::Name"

If you didn't multi-part module names, you're going to get a surprise in
the second case. But, by supplying the third parameter, we can make
split give us what we need.

G. Wade
-- 
Controlling complexity is the essence of computer programming
                                                  -- Brian Kernighan


More information about the Houston mailing list