I'm trying to parse some \x00
null-delimited data. I thought that in a -pe/-ne
loop, $_
would be equivalent to .*
in the pattern matching side of a substitution regex... However as my example shows, they are not the same...
# ↓↓‾‾ works, but is not a regex
printf 'aaa\n\0bbb\n\0' | perl -ne 'BEGIN{ $/="\0"; }; s/$_/\"$.$&\"/ and print;' |xxd
printf 'aaa\n\0bbb\n\0' | perl -ne 'BEGIN{ $/="\0"; }; s/.*/\"$.$&\"/ and print;' |xxd
# ↑↑__ gives un-expected output
# output # ↓ ↓
0000000: 2231 6161 610a 0022 2232 6262 620a 0022 "1aaa..""2bbb.."
0000000: 2231 6161 6122 0a00 2232 6262 6222 0a00 "1aaa".."2bbb"..
# ↑ ↑
What is needed to get an s/ / /
type of substitution to recognize the full $_
?