I'm a learner myself, but here is a quick guess:
open(IN,"/etc/httpd/conf/httpd.conf") || die $!;
@conf = <IN>;
close(IN);

foreach (@conf) {
    if ($_ =~ /ServerName (.*)/i) {
    push (@servers,$1);
    }
}
print "@servers\n";

You may also need to put in a exclusion for the main servername directive at
the beginning of the conf file if you don't want that included in your list.
This example also assumes that there is only 1 space between the server name
and the actual server name.

Hope this helps,
--Bill



----- Original Message -----
From: "Tyler Longren" <[EMAIL PROTECTED]>
To: "Perl Beginners" <[EMAIL PROTECTED]>
Sent: Thursday, June 28, 2001 9:44 AM
Subject: arrays


Hello everyone,

I'm just starting perl.  I want to search through httpd.conf and get the
ServerName from each virtual host.
Ex:
<VirtualHost *>
        DocumentRoot /home2/ploo.net/www
        ServerName www.ploo.net
        CustomLog /home2/ploo.net/logs/access_log
        ErrorLog /home2/ploo.net/logs/error_log
        TransferLog /home2/ploo.net/logs/transfer_log
        ScriptAlias /cgi-bin/ /home2/ploo.net/cgi-bin/
</VirtualHost>
<VirtualHost *>
        DocumentRoot /home2/test.net/www
        ServerName www.test.net
        CustomLog /home2/test.net/logs/access_log
        ErrorLog /home2/test.net/logs/error_log
        TransferLog /home2/test.net/logs/transfer_log
        ScriptAlias /cgi-bin/ /home2/test.net/cgi-bin/
</VirtualHost>

Could I get the ServerName values put into an array so I can do something
with each different ServerName?  Thank you everyone.

Tyler



Reply via email to