Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found