[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Split versus Join



Something to watch out for is the syntax differences
between SPLIT and JOIN.  I recently was programming and
suffering through the flu and I began to use the double
quote syntax in the SPLIT command.  SPLIT _WILL_ take this
but the results are really strange.  Since I was doing a
very large number of SPLITs and JOINs on information in
files - I thought I'd pass this along.  My offending
statement was:

	@theLine = split( ")", $theCommand );

Looks innocent enough, but Perl complains about an extra
closing ")".  It also gives the wrong line number for the
error.  Usually two lines back from where the error
occurs.  In my flu induced delusion I decided that I needed
to change the line to:

	@theLine = split( "\)", $theCommand );

No luck.  So I tried:

	@theLine = split( '\)', $theCommand );

Perl loves this.  :-)  But everything went south as far as
data integrity.  It was at this point that I realized I was
using a JOIN syntax for the SPLIT command and put in the
correct line:

	@theLine = split( /\)/, $theCommand );

You still need the backslash though.  :-)