I am trying to use Perl's in-place-editing feature to change some text in files with Unix line endings in a PowerShell session on Windows:
perl.exe -i'.bak' -p -e "s#PATTERN#REPLACEMENT#g" (get-childItem *.sql,*/*.sql)
Unfortunately, the line endings are changed from Unix to Windows.
Is there an option to tweak this one liner so that it doesn't modify the line endings?
Normally, on Windows, the
:crlfPerlIO layer is used by default, which converts to and from CRLF line endings in the file to LF in the stringsperlsees. Traditionally, the:rawPerlIO layer would be used to prevent this, but according to the documentation:You can use the
openpragma to change the default layers for opening files (And/or use the three argument version ofopento customize them on a per-file basis).In my testing (using Strawberry Perl 5.32), using
:perliowith that pragma still did line ending conversion despite the above, so:rawit is. (However,perlioworks with thePERLIOenvironment variable. It looks like when set that way it replaces the default layers, when used with the pragma it appends to the defaults instead despite what the documentation suggests.)So,
or