diff options
author | Kriton Kyrimis <kyrimis@princeton.edu> | 1988-02-01 04:35:21 +0000 |
---|---|---|
committer | Larry Wall <lwall@jpl-devvax.jpl.nasa.gov> | 1988-02-01 04:35:21 +0000 |
commit | 9bb9d9f726fa55c70ed76abad9fe7c61d4eb4182 (patch) | |
tree | b31ea68d7f4dc2e2d30b150698df92735e4c251a /perl.man.2 | |
parent | 83b4785aebef542ad391e53b49c107fc5e1b4a58 (diff) | |
download | perl-9bb9d9f726fa55c70ed76abad9fe7c61d4eb4182.tar.gz |
perl 1.0 patch 12: scripts made by a2p doen't handle leading white space right on input
Awk ignores leading whitespace on split. Perl by default does not.
The a2p translator couldn't handle this. The fix is partly to a2p
and partly to perl. Perl now has a way to specify to split to
ignore leading white space as awk does. A2p now takes advantage of
that.
I also threw in an optimization that let's runtime patterns
compile just once if they are known to be constant, so that
split(' ') doesn't compile the pattern every time.
Diffstat (limited to 'perl.man.2')
-rw-r--r-- | perl.man.2 | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/perl.man.2 b/perl.man.2 index 25f3c26469..05eb4a9130 100644 --- a/perl.man.2 +++ b/perl.man.2 @@ -1,7 +1,10 @@ ''' Beginning of part 2 -''' $Header: perl.man.2,v 1.0.1.2 88/01/30 17:04:28 root Exp $ +''' $Header: perl.man.2,v 1.0.1.3 88/02/01 17:33:03 root Exp $ ''' ''' $Log: perl.man.2,v $ +''' Revision 1.0.1.3 88/02/01 17:33:03 root +''' patch12: documented split more adequately. +''' ''' Revision 1.0.1.2 88/01/30 17:04:28 root ''' patch 11: random cleanup ''' @@ -333,8 +336,25 @@ Anything matching PATTERN is taken to be a delimiter separating the fields. (Note that the delimiter may be longer than one character.) Trailing null fields are stripped, which potential users of pop() would do well to remember. -A pattern matching the null string will split the value of EXPR into separate -characters. +A pattern matching the null string (not to be confused with a null pattern) +will split the value of EXPR into separate characters at each point it +matches that way. +For example: +.nf + + print join(':',split(/ */,'hi there')); + +.fi +produces the output 'h:i:t:h:e:r:e'. + +The pattern /PATTERN/ may be replaced with an expression to specify patterns +that vary at runtime. +As a special case, specifying a space ('\ ') will split on white space +just as split with no arguments does, but leading white space does NOT +produce a null first field. +Thus, split('\ ') can be used to emulate awk's default behavior, whereas +split(/\ /) will give you as many null initial fields as there are +leading spaces. .sp Example: .nf |