#!/usr/bin/env perl
use Modern::Perl qw /2014/;
my $iniprod = 'php.ini-production';
my $ininocm = 'php.ini-nocomments';
open my $IN, '<', $iniprod or die "Could not open $iniprod for readin
+g: $!";
open my $OUT, '>', $ininocm or die "Could not open $ininocm for writin
+g: $!";
while (<$IN>) {
print $OUT $_ unless /;\s+/ ;
}
close $IN or die "Error closing $iniprod: $!";
close $OUT or die "Error closing $ininocm: $!";
results:
[/etc/php.d] # ./php.ini-remove-comments.pl
Can't locate Modern/Perl.pm in @INC (@INC contains: /usr/local/lib64/p
+erl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/p
+erl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./php.ini-re
+move-comments.pl line 2.
BEGIN failed--compilation aborted at ./php.ini-remove-comments.pl line
+ 2.
I checked...
[/etc/php.d] # perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
The release date for 5.10.1 was 2009-Aug-06. Apparently a lot has changed in 5 years... latest version at 5.21.3?
I commented 'use Modern::Perl qw /2014/;' and it worked perfectly--except it left blank lines like tombstones where the comments used to be.
I thought another pass would do it:
1 #!/usr/bin/env perl
2 # use Modern::Perl qw /2014/;
3
4 my $iniprod = 'php.ini-production';
5 my $ininocm = 'php.ini-nocomments';
6
7 open my $IN, '<', $iniprod or die "Could not open $iniprod fo
+r reading: $!";
8 open my $OUT, '>', $ininocm or die "Could not open $ininocm fo
+r writing: $!";
9
10 while (<$IN>) {
11 print $OUT $_ unless /;\s+/;
12 }
13 while (<$OUT>) {
14 print $OUT $_ unless /\n+/;
15 }
16 close $IN or die "Error closing $iniprod: $!";
17 close $OUT or die "Error closing $ininocm: $!";
18
did not work. I tried to come up with something like this...
#!/usr/bin/env perl
# use Modern::Perl qw /2014/;
my $iniprod = 'php.ini-production';
my $ininocm = 'php.ini-nocomments';
open my $IN, '<', $iniprod or die "Could not open $iniprod for readin
+g: $!";
open my $OUT, '>', $ininocm or die "Could not open $ininocm for writin
+g: $!";
while (<$IN>) {
if (!$_ /;\s+/) {
print $OUT $_
}
}
close $IN or die "Error closing $iniprod: $!";
close $OUT or die "Error closing $ininocm: $!";
but I'm getting an error...
Substitution pattern not terminated
Is this any different form 'print OUT $_ unless...' ?
Should I use chomp here? |