ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
8.9. Processing Variable-Length Text FieldsProblemYou want to extract variable length fields from your input. SolutionUse # given $RECORD with field separated by PATTERN, # extract @FIELDS. @FIELDS = split(/PATTERN/, $RECORD); DiscussionThe If your input field separator isn't a fixed string, you might want split(/([+-])/, "3+5-2"); returns the values: (3, '+', 5, '-', 2) To split colon-separated records in the style of the /etc/passwd file, use: @fields = split(/:/, $RECORD); The classic application of @fields = split(/\s+/, $RECORD); If @fields = split(" ", $RECORD); This behaves like When the record separator can appear in the record, you have a problem. The usual solution is to escape occurrences of the record separator in records by prefixing them with a backslash. See Recipe 1.13. See AlsoThe |