CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
remove block of text (Apache Virtual hosts config)

 



xyon
New User

Apr 1, 2008, 7:25 AM

Post #1 of 2 (293 views)
remove block of text (Apache Virtual hosts config) Can't Post

Hello all,

I've got a task to be done that perl could do very nicely, although I'm just stumped on exactly how to do it.

I have a config file like so:

Code
<Location /sessions/ceasar> 
SSLRequireSSL
AllowOverride None
Options MultiViews Indexes
Allow from all
Deny from none
AuthName "ceasar"
Include /etc/httpd/includes/auth.conf
require user ceasar
</Location>
<Location /sessions/spartan>
SSLRequireSSL
AllowOverride None
Options MultiViews Indexes
Allow from all
Deny from none
AuthName "spartan"
Include /etc/httpd/includes/auth.conf
require user spartan
</Location>


I would like to be able to delete an assigned user's config (ie, "ceasar"). I can match on "<Location /sessions/$name>", but am unaware as to how to delete the following 9 lines.

Here is what I've got so far:


Code
    if ($name) { 
open(CFGFILE, "$config") or die "$!";
foreach my $line (<CFGFILE>) {
if ("$line" = "/<Location /sessions/$name>") {
};
};
close CFGFILE;
# Below is if I stored the file into an array (or used Tie::File), but not sure
# how to delete 9 proceeding lines from the match.
# @lines = grep(!/<Location \/sessions\/$name>/, @lines);
};



KevinR
Veteran


Apr 1, 2008, 11:05 AM

Post #2 of 2 (287 views)
Re: [xyon] remove block of text (Apache Virtual hosts config) [In reply to] Can't Post

You could probably use the splice() function if you have the file in an array or are using Tie::File. You could also use perls inplace editor. If I have time later today I will write some code using the inplace editor that will do this.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives