in reply to AnyEvent::Socket -> Hosts File -> CR/LF Issue on windows?
Is this a mistake in this module? Or have I somehow messed up and perl on windows? Is perl meant to treat '\n' in regex as '\r\n' when running on windows?
As others have pointed out, Perl normally uses the :crlf PerlIO layer on Windows. However, if you look at how _parse_hosts gets called, it's using AnyEvent::IO's aio_load, which does open $fh, "<:raw:perlio", or AFAICT its XS equivalent when the IO::AIO backend is used. So while you could hack it by changing the file to use LF instead of CRLF - I have no idea whether other Windows libraries will like that, though! - or by monkey-patching _parse_hosts*, I'm not sure you'll be able to change this behavior without getting in touch with the module's author.
* Just for fun, this ugly hack should work:
{ my $oldsub = \&AnyEvent::Socket::_parse_hosts; no warnings 'redefine'; *AnyEvent::Socket::_parse_hosts = sub ($) { (my $in = shift) =~ s/\r\n/\n/g; $oldsub->($in) }; }
Update: Looking at the code, another possible workaround is to point the environment variable PERL_ANYEVENT_HOSTS at a hosts file that has only LF line endings.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: AnyEvent::Socket -> Hosts File -> CR/LF Issue on windows? (updated)
by sectokia (Friar) on Feb 09, 2022 at 10:12 UTC |