hudsterboy has asked for the wisdom of the Perl Monks concerning the following question:
Yes, I am confused. Just starting to play with perl and trying to do something clever (for me, anyway).
Basically, trying to extract this string:server1 server2 server3
Easy (even for me) however IF there is a "webserver#" entry, I want different results. I want this string:server1:NY:3600 server2:NY:3600 server3:NY:3600 server4:Boston:3600
"webserver1 server2 server3 webserver4"
In other words, extract "webserverx" but NOT "serverx"server1:NY:3600 webserver1:NY:3600 server2:NY:3600 server3:NY:3600 webserver4:NY:3600 server4:Boston:3600
There is probably a hundred ways of doing this, but every time I go down a path, I get stuck. I'm getting very frustrated. I know I could do this with a shell script, but I really want to start using perl. This is my last resort.
Any help with where to start will be greatly appreciated. This is what I have so far. Am I going down the right path?:
#!/usr/bin/perl # stuff use warnings; use strict; open(SRVS, "< /opt/etc/servers") || die "Can't open /opt/etc/servers"; my $wserv = 0; my @allserv = (); while (my $line = <SRVS>) { if ($line =~ /server/) { if ($line =~ /web/) { @webserv = split(":", $line); $wserv = 1; push(@allserv, $webserv[0]); } else { $wserv = 0; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data manipulation confusion
by ikegami (Patriarch) on Mar 10, 2010 at 21:42 UTC | |
by hudsterboy (Initiate) on Mar 11, 2010 at 04:52 UTC | |
by ikegami (Patriarch) on Mar 11, 2010 at 05:35 UTC | |
|
Re: Data manipulation confusion
by raghu_shekar (Novice) on Mar 11, 2010 at 04:54 UTC | |
by ikegami (Patriarch) on Mar 11, 2010 at 05:38 UTC |