| Separator Value | Mode | Description |
$/ = undef; | Slurp mode | Reads the entire file into a single string all at once. |
$/ = ""; (empty string) | Paragraph mode | Reads text block-by-block, delimited by two or more newlines. |
$/ = "\n"; (default) | Line-by-line mode | Reads one standard line at a time. |
$/ = " "; (space) | Space-delimited mode | Reads characters up to the next space (sometimes referred to as "almost word-by-word"). |
$/ = "\0"; | Null-terminated mode | Reads up to a null character. Extremely useful for processing output from system commands like find -print0. |
$/ = \32768; (scalar ref) | Fixed-length mode | Passing a reference to an integer (e.g., \1024) reads exactly that many bytes at a time. Great for fixed-width data or binary files. |
Wednesday, April 13, 2011
Understanding Perl Input Record Separators ($/)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment