in reply to Re^3: regex basics
in thread regex basics
CountZero, did you say !$_ /;\s+/ is invalid syntax?
And here I was all ready to use this on other config files. If fact, I already have:
It seems to work... but please show me the correct negation syntax before the code police smash in my door, drag me off to a detention camp and force me to write JavaScript.#!/usr/bin/env perl use strict; use warnings; my $conforig = 'httpd.conf-orig'; my $confnocm = 'httpd.conf-nocomments'; open my $IN, '<', $conforig or die "Could not open $conforig for reading: $!"; my $text; while (<$IN>) { if (!/\#\s+/) { $text .= $_; } } close $IN or die "Error closing $conforig: $!"; # remove blank lines $text =~ s{\n{2,}}{\n}gm; open my $OUT, '>', $confnocm or die "Could not open $confnocm for writing: $!"; print $OUT $text; close $OUT or die "Error closing $confnocm: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: regex basics
by choroba (Cardinal) on Feb 02, 2015 at 15:28 UTC | |
by AnomalousMonk (Archbishop) on Feb 02, 2015 at 19:13 UTC | |
by Anonymous Monk on Feb 04, 2015 at 07:18 UTC |