Just to let you know, I'm sorted now. Thanks to all who helped, there are some nice innovative ideas in the answers.
Spike.

Hello World!

This question sounds simple, but when you look into it, you'll realise that there's more to it than first appears. If you run a script from the DOS command line with arguments, the arguments go into @ARGV in EXACTLY the right manner for my application.

Example:
my-script.pl one two "three four" five
will give an @ARGV array like this:
one, two, three four, five

I am trying to replicate this with a GUI, getting the information with a TK Entry widget. Unfortunately the widget will not allow me to assign it's data to an array, so I need to convert the data from it's string to an array.

my $entry=$mw->Entry(-textvariable=>\$string)->pack();
If I use split, like this:
@array = split (' ', $string);
Then a string of:
one two "three four" five
becomes
one, two, "three, four", five

I did start looking at looping through this incorrect array, and creating a new 'corrected' one, but when I realised what this entails, I found it was getting a little close to my limit, especially when I worked out all the considerations that need making. This is the sort of string it would have to cope with:
one "two three" fo"ur "five si"x seven "eight
Giving an array of:
one, two three, fo, ur , five, si, x seven , eight

Any help would be much appreciated.

S.

Edit by Chady -- added code tags.


In reply to Convert a string to an array? by spikey_wan

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.