Project

General

Profile

Actions

Feature #12926

closed

-l flag for line end processing should use chomp! instead of chop!

Added by josh.cheek (Josh Cheek) over 7 years ago. Updated about 7 years ago.

Status:
Closed
Target version:
-
[ruby-core:78099]

Description

Using chop! can mess up the final line of input because it may not end in a line-end character.

printf a\\nb\\nc | ruby -lne 'p $_'
"a"
"b"
""


$ printf a\\nb\\nc\\n | ruby -lne 'p $_'
"a"
"b"
"c"

Using chomp! works correctly in both cases.

$ printf a\\nb\\nc | ruby -ne '$_.chomp!; p $_'
"a"
"b"
"c"

$ printf a\\nb\\nc\\n | ruby -ne '$_.chomp!; p $_'
"a"
"b"
"c"
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0