Skip to main content
edited body
Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

...Testing Raku's -pe flags under zsh to visualize input with no EOF newline:

~ % printf 'cat\nmouse'
cat
mouse%
~ % printf 'cat\nmouse' | raku -pe ''
cat
mouse

Raku performs Unicode NFC Normalization by default, so it's a good choice if you input isn't normalized (this feature can be defeated if necessary). Above shows the default behavior of Raku's -pe flags is to add an EOF newline if none is present. AFAIK this behavior differs from Perl (tested with perl_v5perl v5.34.3).


...this time under zsh using Raku's slurp function:

 ~ % printf 'cat\nmouse'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.print;'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.put;'
cat
mouse

Raku has two commonly used output functions: print which doesn't add a trailing \n newline, and put which does add a trailing \n newline. Think of put as an acronym standing for Print"Print-Using-Terminator".

Thus it's fairly easy to clean up messy newlines at the EOF. Below (last code example) shows how to trim-trailing (multiple) newlines then add back a single newline using put:

~ % printf 'cat\nmouse\n\n'
cat
mouse

 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.print;'
cat
mouse%
 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.put;'
cat
mouse

Tested under zsh 5.9 (x86_64-apple-darwin22.0)

https://docs.raku.org
https://raku.org

Using Raku (formerly known as Perl_6)

...Testing Raku's -pe flags under zsh to visualize input with no EOF newline:

~ % printf 'cat\nmouse'
cat
mouse%
~ % printf 'cat\nmouse' | raku -pe ''
cat
mouse

Raku performs Unicode NFC Normalization by default, so it's a good choice if you input isn't normalized (this feature can be defeated if necessary). Above shows the default behavior of Raku's -pe flags is to add an EOF newline if none is present. AFAIK this behavior differs from Perl (tested with perl_v5.34.3).


...this time under zsh using Raku's slurp function:

 ~ % printf 'cat\nmouse'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.print;'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.put;'
cat
mouse

Raku has two commonly used output functions: print which doesn't add a trailing \n newline, and put which does add a trailing \n newline. Think of put as an acronym standing for Print-Using-Terminator".

Thus it's fairly easy to clean up messy newlines at the EOF. Below (last code example) shows how to trim-trailing (multiple) newlines then add back a single newline using put:

~ % printf 'cat\nmouse\n\n'
cat
mouse

 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.print;'
cat
mouse%
 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.put;'
cat
mouse

Tested under zsh 5.9 (x86_64-apple-darwin22.0)

https://docs.raku.org
https://raku.org

Using Raku (formerly known as Perl_6)

...Testing Raku's -pe flags under zsh to visualize input with no EOF newline:

~ % printf 'cat\nmouse'
cat
mouse%
~ % printf 'cat\nmouse' | raku -pe ''
cat
mouse

Raku performs Unicode NFC Normalization by default, so it's a good choice if you input isn't normalized (this feature can be defeated if necessary). Above shows the default behavior of Raku's -pe flags is to add an EOF newline if none is present. AFAIK this behavior differs from Perl (tested with perl v5.34.3).


...this time under zsh using Raku's slurp function:

 ~ % printf 'cat\nmouse'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.print;'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.put;'
cat
mouse

Raku has two commonly used output functions: print which doesn't add a trailing \n newline, and put which does add a trailing \n newline. Think of put as an acronym standing for "Print-Using-Terminator".

Thus it's fairly easy to clean up messy newlines at the EOF. Below (last code example) shows how to trim-trailing (multiple) newlines then add back a single newline using put:

~ % printf 'cat\nmouse\n\n'
cat
mouse

 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.print;'
cat
mouse%
 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.put;'
cat
mouse

Tested under zsh 5.9 (x86_64-apple-darwin22.0)

https://docs.raku.org
https://raku.org

Source Link
jubilatious1
  • 3.9k
  • 10
  • 20

Using Raku (formerly known as Perl_6)

...Testing Raku's -pe flags under zsh to visualize input with no EOF newline:

~ % printf 'cat\nmouse'
cat
mouse%
~ % printf 'cat\nmouse' | raku -pe ''
cat
mouse

Raku performs Unicode NFC Normalization by default, so it's a good choice if you input isn't normalized (this feature can be defeated if necessary). Above shows the default behavior of Raku's -pe flags is to add an EOF newline if none is present. AFAIK this behavior differs from Perl (tested with perl_v5.34.3).


...this time under zsh using Raku's slurp function:

 ~ % printf 'cat\nmouse'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.print;'
cat
mouse%
 ~ % printf 'cat\nmouse' | raku -e 'slurp.put;'
cat
mouse

Raku has two commonly used output functions: print which doesn't add a trailing \n newline, and put which does add a trailing \n newline. Think of put as an acronym standing for Print-Using-Terminator".

Thus it's fairly easy to clean up messy newlines at the EOF. Below (last code example) shows how to trim-trailing (multiple) newlines then add back a single newline using put:

~ % printf 'cat\nmouse\n\n'
cat
mouse

 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.print;'
cat
mouse%
 ~ % printf 'cat\nmouse\n\n' | raku -e 'slurp.trim-trailing.put;'
cat
mouse

Tested under zsh 5.9 (x86_64-apple-darwin22.0)

https://docs.raku.org
https://raku.org