Array from a string.

From: Richard S Beckett (spikeywan_at_bigfoot.com.delete.this.bit)
Date: 03/31/04


Date: Wed, 31 Mar 2004 15:31:45 +0100

I've written a nice little script, and it gets it's array of data from the
command line arguments.

If you enter something like this: myscript.pl one two "three four" five

then the @ARGV array will contain:

one

two

three four

five

Which is EXACTLY what I want.

Now, as people seem to have an aversion to DOS these days, I've added a GUI
to the script, so that running it with no arguments fires up the gui
version.

I get my aray from an entry box...

my $entrybox = $mw -> Entry(-textvariable => \$array) -> pack();

The problem is I can't use an array for the text variable, so I have to
convert the string $array into @array.

If I do this:

@array = split(' ', $array);

Entering: one two "three four" five

gives @array of:

one

two

"three

four"

five

I was just trying to sort this out, when I realised it's an absolute
nightmare if I loop through @array, and try to if /^\".*\"/ etc.

Is there an easy way to do this?

Thanks,

--
R.
GPLRank +79.699


Relevant Pages

  • Re: Referencing Korn Shell Array Names as a Variable
    ... Your idea worked for displaying the output from the command. ... $ echo $ ... # Attempt to use variable array name and index to reference array value ... The issue is with this line of the script ...
    (comp.unix.shell)
  • Re: Editable input from the console windows
    ... I learning the syntax and build upon a previously working script. ... My case, read, and history statements are mucked up. ... # The code block that the populate the array with id3tag data has been remove. ... You are passing the entire contents of $VAR as a command name (by ...
    (comp.unix.shell)
  • Re: string retrieval issue
    ... Chicago Bears|NFC North ... not writing the third element back to the array). ... You didn't include it in your script. ... Fear is the mind-killer. ...
    (comp.lang.perl.misc)
  • Re: Problem printing array content with CGI
    ... If a CGI works from a command line but not when called by a web server ... > to exec a script, gets the output back in a array, ... > and prints out the content of the array using CGI. ...
    (comp.lang.perl.misc)
  • Re: even rows for checkbox forms with no splitting of boxes from values
    ... 'mod' on the array length with a denominator equal to the width of the row, ... State saving really depends on what the script is already doing. ... So I usually roll my own checkboxes. ... #this is to create an array with 25-50 strings 2-10 in length ...
    (comp.infosystems.www.authoring.cgi)