This can be done with the command line switches -l
and -0
, or by manually changing $/
.
-l
and -0
are order dependent and can be used multiple times.
Thanks for inspiring me to read perlrun documentation.
examples:
# -0 : set input separator to null
# -l012 : chomp input separator (null)
# and set output separator explicitly to newline, octol 012.
# -p : print each line
# -e0 : null program
perl -0 -l012 -pe0 < /proc/$$/environ
.
# -l : chomp input separator (/n) (with -p / -n)
# and set output separator to current input separator (/n)
# -0 : set input separator to null
# -p : print each line
# -e0 : null program
perl -l -0 -pe0 < /proc/$$/environ
.
# partially manual version
# -l : chomp input separator (/n) (with -p / -n)
# and set output separator to current input separator (/n)
# -p : print each line
# -e : set input record separator ($/) explicitly to null
perl -lpe 'INIT{$/="\0"}' < /proc/$$/environ
bundling issues:
# DOESN'T WORK:
# -l0 : chomp input separator (/n) (with -p / -n)
# and set output separator to \0
# -e0 : null program
perl -l0 -pe0
.
# DOESN'T WORK:
# -0 : set input separator to null (\0)
# -l : chomp input separator (\0) (with -p / -n)
# and set output separator to current input separator (\0)
# -e0 : null program
perl -0l -pe1