
Help - Split Function Blowing My Mind Away!!
[Posted and a courtesy copy mailed.]
Quote:
> > The first argument to split(), though for historical reasons often
> > written as a string, is really a regular expression. The vertical bar
> > is a regular-expression metacharacter.
> > Write that line thus:
> > And all will be well. (This is on my Top Ten list of Perl surprises for
> > beginners. The vertical bar is a popular field separator!)
> If you really have such a list, I'd be very interested in seeing it.
Well, I'll show them, in no particular order. I'm sure others will be
able to slice and dice, transmogrify and improve.
I put this list together without looking at the 'Common Goofs for
Novices' section in the Blue Camel (page 528 et seq.). These are my
informal recollections from comp.lang.perl.misc.
Not included are mechanical failures, such as syntax errors, failure to
use '-w' and 'use strict;', etc. Those in the list are all semantic
errors, unremarked at run time except by bad results.
Also not included are performance botches (such as hideous sorts with
repeated complex key extraction) or poor algorithms (such as character-
at-a-time processing where functions would do the job), or style errors
(lower-case filehandles, upper-case variables, uninterpolating double-
quoted strings).
Failure to check for failure of system calls.
Failure to chomp() input lines.
Failure to binmode() a binary file.
Failure to escape metacharacters in split().
Failure to prefix directory before file tests using readdir().
Use of ==, etc. instead of eq, etc.
Use of = instead of == or eq.
Use of captured variables from regex match without checking for success.
Y2K and month-1 errors using localtime().
Confusion of Boolean tests for true/false, defined(), exists().
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/