Hi CountZero and thanks for the reply.

I tried this (using CentOS 6.6):

#!/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?


In reply to Re^2: regex basics by jott19
in thread regex basics by jott19

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.