On Thu, Jul 14, 2016 at 10:50 AM, Darryl Philip Baker
<[email protected]> wrote:
While not truly a beginner it feels that way after not doing anything
substantial in Perl in many years.
I currently need a program to take Apache HTTPD configuration files in HTTPD
2.2 syntax used in current production and convert them to HTTPD 2.4 syntax in
future production. I will need to do this many times weekly until we cut over
to the new systems. My first challenge is converting the permissions syntax:
Order deny,allow
Deny from all
To
Require all denied
Why not go line by line? Not 100% certain on the Apache syntax, but in your
while loop where you are processing line by line:
next if /Order\s+deny,\s*allow/i; # Skip it in the output
if( /(\s*)Deny\s+from\s+all/i) {
my $leading_whitespace = $1; # Preserve whatever whitespace is in the file
now, could be multiple tabs and or spaces
print $leading_whitespace . "Require all denied";
}
Learning from that example I came up with:
$prevline = $_; # Save current line for later
if needed
# Change:
# Order deny,all
# Deny from all
# To:
# Require all denied
# No matter what case the first letters are
if ( /Order\s+Deny,\s*Allow/i ) {
next;
chomp $_;
if ( /(\s)Deny\s+from\s+All/i) {
$whitespace = $1;
print $whitespace, "Require all denied \# New Syntax\n";
next;
chomp $_;
} else {
print $prevline, " \# Old Syntax\n";
}
}
It is not doing the expected. The “Order deny,allow” line is never output and
where I want “Require all denied” the “Deny from all” is still being output.
Darryl Baker
PMOET -DAPS
X76674