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) about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
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