I an using split to break strings like these:
Resource Group: gr_shared_fs rs_ipaddr (heartbeat::ocf:IPaddr): Started lapg2-a rs_raid1_shared_fs (heartbeat::ocf:Raid1): Started lapg2- +a rs_fs_shared (heartbeat::ocf:Filesystem): Started lapg2- +a
into blocks separated by space. Please note the white space in front of the rs_ starting strings (below "Reso" from the first line). That white space may or may not be there. I need to split the strings and I am using this:
my @statusLineFields = split(/\s+/, $statusLine);
but it seems if I do have that white space there the first element in @statusLineFields is whitespace. If the input lines do not have any leading space then the first element is some rs_ string. I really need to ignore that white space and have the first element be the rs_ string somehow.

I have the feeling this is a 1-line quick and easy answer but I've been running circles around my tail and couldn't figure it. In addition to this, once I split the line, the elements of that array (with or without the first one being whitespace) are surrounded by one blank space on each side. That "Started" is actually " Started ". Why is this and how do I get rid of it?

Thanks!


In reply to Another question about the split function by RaduH

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.