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: Logon script - function array and select case not working
    ... this all works well, except, the function i am using for the rules in the control script causes alot of querrys to AD. as there are alot of groups. ... objTSout.writeline retrv ... So if you think that this will assign an array value to the variable, how do you think the case select statement is going go compare this array value with the literal string values such as "group name here"? ... However, by not assigning ANY value to checkgrp in the function, you are guaranteeing that, should the function ever exit, it will return no information. ...
    (microsoft.public.scripting.vbscript)
  • 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)