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
> 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?
Yes there is. It is called checking the FAQ list before posting:
perldoc -q inside
--
A. Sinan Unur
1u...@llenroc.ude (reverse each component for email address)
See the FAQ, as Sinan suggested.
A 'regexish' application of the FAQ answer may be:
my @array;
push @array, $+ while $array =~ /"([^"]+)"|(\S+)/g;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
How do you know I didn't?
> perldoc -q inside
Now, there's a word I would _never_ have associated with this problem,
thanks.
R.
Frankly, neither would have I. But perldoc -q split and perldoc -q
delimited would have given you the same thing. :-P
Paul Lalli
There are many ways of looking for what you need in the FAQ list. What I
gave you is a short-cut that one figures out after finding the entry for
the first time.
The first time I found that entry was by reading through perlfaq4:
DESCRIPTION
This section of the FAQ answers questions related to manipulating
numbers, dates, strings, arrays, hashes, and miscellaneous data
issues.
Hmmmm .. You would have found the answer had you looked at the table of
contents and then read perlfaq4.
OK, it's a fair cop! :-) I'll try harder next time.
Thanks for the help.
--
R.
GPLRank +79.699
perldoc -q string
would do it too, and the OP might have thought of that search
term since he used it in the Subject: himself. :-)
--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas
Jeesh.
"Richard S Beckett" <spik...@bigfoot.com.delete.this.bit> wrote in message
news:c4euhp$dfo$1...@newshost.mot.com...
Why?
The OP can just read the FAQ themselves once they have been pointed to it.
What's the point of repeating the answer in a post?
[snip a full quote]
Please don't do that.
--
Sam Holden
SoCalSam wrote:
> 6 posts telling the poor dude to read the FAQ. Couldn't the first
> responder just answer the Q, and end their post with a friendly
> reminder to read the FAQ?
You don't know much about how Usenet posts are propagated, do you?
jue