in reply to Read in hostfile, modify, output
Also, (#)? would be more readable as (#?) , as you want to match the octothorpe if present, not to match it always, but maybe zero times.
You correctly used a lexical filehandle for the input. Use a lexical filehandle for the output, too.
The preferred way of processing files, though, is to read them line by line if possible. You need to print to a temporary file, as you can't read a file and print to it at the same time.
#!/usr/bin/perl use warnings; use strict; my $file = 'C:/Windows/System32/drivers/etc/hosts'; my %replace = ( '#' => q(), '' => '#' ); open my $In, '<', $file or die $!; open my $Out, '>', "$file.new" or die $!; while (<$In>) { s/(#?)(10\.10\.1\.2)/$replace{$1}$2/; print {$Out} $_; } close $Out or die $!; rename "$file.new", $file or die $!;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|