My script involves opening a data file which has the following format:

q1:The cow jumped over the moon a1:a,b,c s1:a,first,b,second,c,third

a1 is an array and s1 is a hash. I want to make things as easy as possible for those who will be creating the data file. Currently, for the script to work there can be no spaces between the commas and the next letter/word.

a1:a,e will work but a1:a, e will not because of the space between the comma and the e.

I am using the following format to make the array: my @array = split (/,/, $value); and my %hash = split (/,/, $value); to create the hash.

I have also tried using split like this: split(/,\s*/, $value) but that didn't work either.

Is there a good way to create both of these that will ignore any spaces in those records?

Say a user creates a record like this:

a1: c, d s1:a, first, b, second, c, third

where he/she inadvertantly puts one or more spaces between the comma and the next letter/word.

Thanks for the input.

Chris


In reply to clearing spaces from data input by chriso

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.