One easier approach:
use Tie::File;
tie( my @array, 'Tie::File', "/path/to/file" )
or die $!;
my $n = 0;
while ( $n <= $#array ) {
if ( $array[$n] =~ /.*[Oo]rder deny,allow(.*)/ and
$n < $#array and $array[$n+1] =~ /[\Dd]eny from all(.*)/ )
{
$n += 2 and print "\tRequire all denied\n";
next;
}
print $array[$n++],"\n";
}
On Thu, Jul 14, 2016 at 7: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
> And similar transformations. I was able to make this modification if I set $/
> = undef and look at the file as a whole. My problem is I really want to
> process the file line by line to remove several <IfDefine BLAH> ...
> </IfDefine> blocks which may have other conditional code blocks contained
> within them. I have considered using two separate scripts and a two pass
> solution but there is a part of me which would rather have a single script do
> it all in one pass.
>
> My current attempt, after several tries, is:
> if ( m/{.*}[Oo]rder deny,allow(.*)\n(.*)[Dd]eny from all(.*)/) {
> print "\tRequire all denied\n";
> next;
> }
> While not causing syntax errors it is not doing what I want either. I am
> probably using the 'm/' incorrectly and need your help.
>
> Darryl Baker
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/