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: Re: [richsark] Help needed for my script: Edit Log



1arryb
User

Apr 21, 2009, 8:04 AM


Views: 6030
Re: [richsark] Help needed for my script

Hi Rich,

You only get the first host from the dnsServers line because that's what you asked for! The regular expression '/dnsServers=(\S+)/' is only looking for the first sequence of non-whitespace characters from the line. Better would be:

Code
... 
##### Parse hostnames from the dnsServers line.
my $serverLine = $getzoneprof[-1];
# You should check that $getzoneprof[-1] actually contains a dnsServers line here.
$serverLine =~ s/dnsServers=//; # Remove the prefix.
my @servers = ();
foreach my $token (split(/,/, $serverLine)) { #split the server line on the commas.
$token =~ /(\S+)/; # Look for the first "word" of the token.
push (@servers, $1) if $1;
}
# You should also check that you got at least 1 server here.
foreach my $dns (@servers) {
# Do something with the dns server.
}


UPDATE: Bugs fixed in the original are marked as bold.

Cheers,

Larry


(This post was edited by 1arryb on Apr 21, 2009, 8:58 AM)


Edit Log:
Post edited by 1arryb (User) on Apr 21, 2009, 8:46 AM
Post edited by 1arryb (User) on Apr 21, 2009, 8:58 AM


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

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