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

from this text:
server1:NY:3600 server2:NY:3600 server3:NY:3600 server4:Boston:3600
Easy (even for me) however IF there is a "webserver#" entry, I want different results. I want this string:
"webserver1 server2 server3 webserver4"

from this:
server1:NY:3600 webserver1:NY:3600 server2:NY:3600 server3:NY:3600 webserver4:NY:3600 server4:Boston:3600
In other words, extract "webserverx" but NOT "serverx"

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; } } }

In reply to Data manipulation confusion by hudsterboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.