in reply to Re: Perl parse text file using hash
in thread Perl parse text file using hash
The first argument to split is a regex unless you want paragraph mode (and you don't)
That isn't what is happening here, this is a different special case documented in `perldoc -f split`:
As another special case, "split" emulates the default beha +vior of the command line tool awk when the PATTERN is either omitt +ed or a string composed of a single space character (such as ' ' o +r "\x20", but not e.g. "/ /"). In this case, any leading whi +tespace in EXPR is removed before splitting occurs, and the PATTER +N is instead treated as if it were "/\s+/"; in particular, this + means that any contiguous whitespace (not just a single space ch +aracter) is used as a separator. However, this special treatment ca +n be avoided by specifying the pattern "/ /" instead of the str +ing " ", thereby allowing only a single space character to be a sep +arator. In earlier Perls this special case was restricted to the u +se of a plain " " as the pattern argument to split; in Perl 5.18.0 + and later this special case is triggered by any expression whi +ch evaluates to the simple string " ". If omitted, PATTERN defaults to a single space, " ", trigg +ering the previously described awk emulation.
The references to awk are probably not very helpful these days, and probably discourage people from reading the rest and using this useful construct.
|
|---|