On Wed, May 30, 2001 at 03:38:35PM -0500, Nichole Bialczyk wrote:
> i'm trying to work my way throuh an existing script and it says
> 
> @array = qw("stuff", "more stuff", "even more stuff");
> 
> what does the qw do?

In your example, it's a broken way of trying to say:

$array[0] = "stuff";
$array[1] = "more stuff";
$array[2] = "even more stuff";

I say broken because qw splits on whitespace, so what you really get
here is:

$array[0] = '"stuff";'
$array[1] = '"more';
$array[2] = 'stuff";'
$array[3] = '"even';
$array[4] = 'more';
$array[5] = 'stuff";';

qw is a shorthand way of initializing an array with individual words,
because it saves you the trouble of having to type all the quotes and
commas.  For example,

@array = qw(stuff more stuff even more stuff);

gives you

$array[0] = "stuff";
$array[1] = "more";
$array[2] = "stuff";
$array[3] = "even";
$array[4] = "more";
$array[5] = "stuff";

But if you need to initialize the array with strings that have
embedded whitespace, then you've got to do it the long way with all
the quotes and commas.  In your example, all you have to do is drop
the qw:

@array = ("stuff", "more stuff", "even more stuff");

Walt

-- 
Walter C. Mankowski
Senior Software Engineer        Myxa Corporation
phone: (610) 234-2626           fax: (610) 234-2640
email: [EMAIL PROTECTED]            http://www.myxa.com

Reply via email to