On Tue, 28 Aug 2001 10:57:52 -0400, Harold Flomerfelt wrote:

>  I am a perl newb, and I want to parse apache server virtual hosts. 
>What I am trying to accomplish is to end up with a hash with domain 
>names as the keys and  complete virtual host entries as the values. 

I'm not sure about your requirements... I'd turn this into a hash of
hashes.

>Everyone I have talked to says that regular expressions are cake, but 
>they still boggle my mind. here's a sample of what I'm trying to 
>parse, in case you aren't familiar with apache config:
>
><VirtualHost 255.255.255.255>
>ServerAdmin [EMAIL PROTECTED]
>DocumentRoot /path/to/files
>ServerName www.domain.com
></VirtualHost>

>  Any help would be muchly appreciated. Even if somebody could just 
>get me started down a decent path, that would be great.


Ok... try this:

my $host;
while(<DATA>) {
     if((($host) = /<VirtualHost\s+(\S+)>/) .. /<\/VirtualHost>/) {
          $hash{$host} .= $_;
    }
}

use Data::Dumper;
print Dumper \%hash;

__DATA__
<VirtualHost 255.255.255.255>
ServerAdmin [EMAIL PROTECTED]
DocumentRoot /path/to/files
ServerName www.domain.com
</VirtualHost>

-- 
        Bart.

Reply via email to