in reply to Read in hostfile, modify, output

Hello razmeth

If you want to keep it short i'd go with a oneliner: -i as described in perlrun let you to specify an additional extension for the backup file.

Also note that, as you are running into an unfriendly OS, you can lost you if use Perl 32bit instead of Perl 64bit: read Re: Cannot execute external process: Win32 Win64 SysWOW64 and System32 redirection and you'll know why i use %WINDIR%\Sysnative\drivers\etc\hosts weird syntax. Other infos at my homenode

The following oneliner comment/uncomment any 10.10.1.2* association in your file

perl -i.OLD -nle "$re=qr(^(#?)\s*(10\.10\.1\.2.*));if(/$re/){$1?print +$2:print qq(#$2)}" %WINDIR%\Sysnative\drivers\etc\hosts

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.