![]() ![]() If LIMIT is negative, it is treated as if it were instead arbitrarily large as many fields as possible are produced. Thus, the LIMIT value 1 means that EXPR may be split a maximum of zero times, producing a maximum of one field (namely, the entire value of EXPR). If LIMIT is specified and positive, it represents the maximum number of fields into which the EXPR may be split in other words, LIMIT is one greater than the maximum number of times EXPR may be split. If omitted, PATTERN defaults to a single space, " ", triggering the previously described awk emulation. In previous versions, and outside the scope of that feature, it exhibits "The "Unicode Bug"" in perlunicode: characters that are whitespace according to Unicode rules but not according to ASCII rules can be treated as part of fields rather than as field separators, depending on the string's internal encoding. In earlier Perls this special case was restricted to the use of a plain " " as the pattern argument to split in Perl 5.18.0 and later this special case is triggered by any expression which evaluates to the simple string " ".Īs of Perl 5.28, this special-cased whitespace splitting works as expected in the scope of "use feature 'unicode_strings'". However, this special treatment can be avoided by specifying the pattern / / instead of the string " ", thereby allowing only a single space character to be a separator. Using split in this fashion is very similar to how qw// works. In this case, any leading whitespace in EXPR is removed before splitting occurs, and the PATTERN is instead treated as if it were /\s / in particular, this means that any contiguous whitespace (not just a single space character) is used as a separator. m and any of the other pattern modifiers valid for qr (summarized in "qr/STRING/msixpodualn" in perlop) may be specified explicitly.Īs another special case, split emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a string composed of a single space character (such as ' ' or "\x20", but not e.g. If PATTERN is /^/, then it is treated as if it used the multiline modifier ( /^/m), since it isn't much use otherwise. Uses empty string matches as separators thus, the empty string may be used to split EXPR into a list of its component characters.Īs a special case for split, the empty pattern given in match operator syntax ( //) specifically matches the empty string, which is contrary to its usual interpretation as the last successful match. Uses the b in 'abc' as a separator to produce the list ("a", "c"). As an example, the following: my = split(/b/, "abc") # ("a", "c") If PATTERN matches the empty string, the EXPR is split at the match position (between characters). The PATTERN need not be constant an expression may be used to specify a pattern that varies at runtime. Note that a separator may be longer than one character or even have no characters at all (the empty string, which is a zero-width match). If only PATTERN is given, EXPR defaults to $_.Īnything in EXPR that matches PATTERN is taken to be a separator that separates the EXPR into substrings (called " fields") that do not include the separator. (Prior to Perl 5.11, it also overwrote with the list in void and scalar context. Splits the string EXPR into a list of strings and returns the list in list context, or the size of the list in scalar context. ![]() # split /PATTERN/,EXPR,LIMIT # split /PATTERN/,EXPR # split /PATTERN/ #split ![]()
0 Comments
Leave a Reply. |