Re: qw with strings containing spaces

2007-08-09 Thread usenet
On Aug 9, 11:58 am, [EMAIL PROTECTED] (Mathew Snyder) wrote:

> What I am doing is declaring an array and assigning the value:
> @array = qw/All "A - H" "I - P" "Q - Z"/;

You don't want qw{} here.  Just do it the brute-force way:

 @array = ("All", "A - H", "I - P", "Q - Z");


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: qw with strings containing spaces

2007-08-09 Thread Mathew Snyder
John W. Krahn wrote:
> Mathew Snyder wrote:
>> I need to populate a select multiple on a web page when it loads with
>> a series
>> of values.  Most of the values will be determined dynamically when the
>> code runs
>> but some are static.  They look like "A - H", "I - P" and "Q - Z". 
>> The spaces
>> are for readability.
>>
>> What I am doing is declaring an array and assigning the value:
>> @array = qw/All "A - H" "I - P" "Q - Z"/;
>> and then pushing the to-be-determined values onto the array later on. 
>> However,
>> when I print this all out while testing, I get each letter, hyphen and
>> quote as
>> individual elements.  I've tried escaping different ways to no avail.
> 
> qw/All "A - H" "I - P" "Q - Z"/
> 
> is the same as saying:
> 
> split ' ', q/All "A - H" "I - P" "Q - Z"/
> 
> so when using qw// there are no strings just whitespace characters and
> non-whitespace characters.  What you want is:
> 
> my @array = ( 'All', 'A - H', 'I - P', 'Q - Z' );
> 
> 
> 
> John


Thanks John and Flemming.  Works now.

Mathew

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: qw with strings containing spaces

2007-08-09 Thread John W. Krahn

Mathew Snyder wrote:

I need to populate a select multiple on a web page when it loads with a series
of values.  Most of the values will be determined dynamically when the code runs
but some are static.  They look like "A - H", "I - P" and "Q - Z".  The spaces
are for readability.

What I am doing is declaring an array and assigning the value:
@array = qw/All "A - H" "I - P" "Q - Z"/;
and then pushing the to-be-determined values onto the array later on.  However,
when I print this all out while testing, I get each letter, hyphen and quote as
individual elements.  I've tried escaping different ways to no avail.


qw/All "A - H" "I - P" "Q - Z"/

is the same as saying:

split ' ', q/All "A - H" "I - P" "Q - Z"/

so when using qw// there are no strings just whitespace characters and 
non-whitespace characters.  What you want is:


my @array = ( 'All', 'A - H', 'I - P', 'Q - Z' );



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: qw with strings containing spaces

2007-08-09 Thread Flemming Greve Skovengaard

Mathew Snyder wrote:

I need to populate a select multiple on a web page when it loads with a series
of values.  Most of the values will be determined dynamically when the code runs
but some are static.  They look like "A - H", "I - P" and "Q - Z".  The spaces
are for readability.

What I am doing is declaring an array and assigning the value:
@array = qw/All "A - H" "I - P" "Q - Z"/;
and then pushing the to-be-determined values onto the array later on.  However,
when I print this all out while testing, I get each letter, hyphen and quote as
individual elements.  I've tried escaping different ways to no avail.

I've looked on PerlMonks and saw a solution which created a scalar with a string
containing each item separated by commas.  It is then run through the split()
function using the commas as the delimiter.  I'd like a more succinct and
cleaner method of doing this though, if possible.

Any ideas?

Mathew


Why not just declare @array like this:
my @array = ("All", "A - H", "I - P", "Q - Z");

and then later push new variables onto it, like so:
push @array, qw/1 2 3/;

--
Flemming Greve Skovengaard   FAITH, n.
a.k.a Greven, TuxPower   Belief without evidence in what is told
<[EMAIL PROTECTED]>  by one who speaks without knowledge,
4011.25 BogoMIPS of things without parallel.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




RE: qw versus qx

2003-07-24 Thread Dan Muey
> 
> Is qw for holding list of data and qx is for running 
> commands? Do they both indicate a list context? Thanks, John

 perldoc -f qq
 perlop "Regexp Quote-Like Operators"

 my @stuff = qw(hi bye joe mama);
 my @cmdln = qx(cat monkey.txt| grep fred);
 my $cmdln = qx(cat monkey.txt| grep fred);
 print qq(I said "Foo you bar" and they were like "no way");

HTH

DMuey
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: qw versus qx

2003-07-24 Thread Hanson, Rob
> Is qw for holding list of data and qx is for running commands?

yes.

> Do they both indicate a list context?

no.

qw{word word} is the same as ('word', 'word')... and qx{foo bar} is the same
as `foo bar`.  qx{} is just there if you need an alternate syntax to ``,
like if you needed to use a backtick in your command.

Rob

-Original Message-
From: JOHN FISHER [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 7:52 AM
To: [EMAIL PROTECTED]
Subject: qw versus qx


Is qw for holding list of data and qx is for running commands?
Do they both indicate a list context?
Thanks,
John



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: qw for variables?

2002-02-19 Thread Andrea Holstein

In article <[EMAIL PROTECTED]> wrote "Dennis G. Wicks" <[EMAIL PROTECTED]>:

> Greetings;
> 
> I can get qw to work for things like
> 
> @n = qw( john jacob jingleheimer schmidt );
> 
> but something like
> 
> @n = qw( $names );
> 
> doesn't work. I get the literal string "$names" in @n!
> 
> What does the equivalent of qw(???) for a variable?
> 
Do you mean that $names contains the string
"john jacob jingleheimer schmidt"

Then split is your friend:
@n = split / /, $names;

Greetings,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw for variables?

2002-02-19 Thread Dennis G. Wicks

The split did the trick, and cut out a few lines of code
also. I had already done some splits and joins to get ready
for qw() which I can n ow delete!

Thanks for the help everyone!
Dennis

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw for variables?

2002-02-19 Thread Johnathan Kupferer

Dennis G. Wicks wrote:

>Greetings;
>
>No, I mean if $names contains "Jesus Mary Joseph" and I do
>
>   my @n = qw( $names );
>
>I want the same results as if I had done
>
>   my @n = qw( Jesus Mary Joseph );
>
>Obviously qw() does not work this way, but I can't find the
>equivalent that does.
>
>Thanks,
>Dennis
>
How about:

my @n = split(/\s+/, $names);

- Johnathan



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: qw for variables?

2002-02-19 Thread Nikola Janceski

you want split then..

my $names = "Jesus Mary Joseph";
my @n = split /\s+/, $names;


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 3:08 PM
To: [EMAIL PROTECTED]
Subject: Re: qw for variables?


Greetings;

No, I mean if $names contains "Jesus Mary Joseph" and I do

my @n = qw( $names );

I want the same results as if I had done

my @n = qw( Jesus Mary Joseph );

Obviously qw() does not work this way, but I can't find the
equivalent that does.

Thanks,
Dennis

>}On Feb 19, 17:47, "=?iso-8859-1?q?Jonathan=20E.=20Paton?=" wrote:
>} Subject: Re: qw for variables?
>> What does the equivalent of qw(???) for a variable?
>
>You mean like:
>
>my @array = ($var1, $var2, $var3);
>
>Jonathan Paton
>
>__
>Do You Yahoo!?
>Everything you'll ever need on one web page
>from News and Sport to Email and Music Charts
>http://uk.my.yahoo.com
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>}-- End of excerpt from "=?iso-8859-1?q?Jonathan=20E.=20Paton?="



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw for variables?

2002-02-19 Thread Jeff 'japhy' Pinyan

On Feb 19, Dennis G. Wicks said:

>No, I mean if $names contains "Jesus Mary Joseph" and I do
>
>   my @n = qw( $names );
>
>I want the same results as if I had done
>
>   my @n = qw( Jesus Mary Joseph );

There's no quoting operator that will do that for you.  I'd suggest using
split().

  my @n = split ' ', $names;

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw for variables?

2002-02-19 Thread Dennis G. Wicks

Greetings;

No, I mean if $names contains "Jesus Mary Joseph" and I do

my @n = qw( $names );

I want the same results as if I had done

my @n = qw( Jesus Mary Joseph );

Obviously qw() does not work this way, but I can't find the
equivalent that does.

Thanks,
Dennis

>}On Feb 19, 17:47, "=?iso-8859-1?q?Jonathan=20E.=20Paton?=" wrote:
>} Subject: Re: qw for variables?
>> What does the equivalent of qw(???) for a variable?
>
>You mean like:
>
>my @array = ($var1, $var2, $var3);
>
>Jonathan Paton
>
>__
>Do You Yahoo!?
>Everything you'll ever need on one web page
>from News and Sport to Email and Music Charts
>http://uk.my.yahoo.com
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>}-- End of excerpt from "=?iso-8859-1?q?Jonathan=20E.=20Paton?="



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw for variables?

2002-02-19 Thread Jonathan E. Paton

> What does the equivalent of qw(???) for a variable?

You mean like:

my @array = ($var1, $var2, $var3);

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: qw for variables?

2002-02-19 Thread Nikola Janceski

qw( john jacob $name ) is equivelent to

('john', 'jacob', '$name')  notice the single quote. The single quotes does
not interpolate (use the special meanings of special charaters, so the $
doesn't designate a varible name it's just a $ character).

see man perlop
or perldoc perlop

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 2:39 PM
To: [EMAIL PROTECTED]
Subject: qw for variables?


Greetings;

I can get qw to work for things like

@n = qw( john jacob jingleheimer schmidt );

but something like

@n = qw( $names );

doesn't work. I get the literal string "$names" in @n!

What does the equivalent of qw(???) for a variable?

Many TIA!
Dennis

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: qw

2001-05-30 Thread Paul


--- Nichole Bialczyk <[EMAIL PROTECTED]> wrote:
> i'm trying to work my way throuh an existing script and it says
> @array = qw("stuff", "more stuff", "even more stuff");

That looks like a typo, though they may have actually wanted the quotes
and commas in the strings if you run that under -w, it'll complain.

By the way, have we mentioned that you should always use strict.pm and
the -w switch? =o) lol
 
> what does the qw do?

qw is the "Quote-Word" operator for perl. c.f. perldoc perlop

qw takes a list of whitespace-delimited strings and quotes them as if
they were each in singleticks. For example:

  @array = qw / a b c d e /;

creates an array of the alphabet's first 5 letters.
The slash isn't magical here; it's just one possible bounding
character. You can use matching pairs () {} <> [] or other things like
/ if those aren't convenient. 

So, to paraphrase the above,
 @array = qw( stuff moreStuff evenMoreStuff );

makes an array of those three elements, but the literal value above
would yield:
  "stuff",
  "more
  stuff",
  "even
  more
  stuff"

Notice that the quotes and commas are part of the strings, and that
"even more stuff" got split into three seperate elements of the array.

Does that help?
Is that the actual code you're looking at?
If not, post it, and let's take it apart! lol



__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: qw

2001-05-30 Thread Walt Mankowski

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 EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




RE: qw

2001-05-30 Thread Jeffrey Goff

Yep,caught that myself a few minutes -after- sending email. Apologies.

-Original Message-
From: Jeff Pinyan [mailto:[EMAIL PROTECTED]]
On May 30, Jeffrey  Goff said:

>It's a shortcut for assigning words to an array. That statement would
return
>an array that looks roughly like this:
>
>('"stuff",', '"more stuff",', '"even more stuff"') # Note the double
quotes.

Nope, no matter what you do, qw() really splits on whitespace.



RE: qw

2001-05-30 Thread Jeff Pinyan

On May 30, Jeffrey  Goff said:

>It's a shortcut for assigning words to an array. That statement would return
>an array that looks roughly like this:
>
>('"stuff",', '"more stuff",', '"even more stuff"') # Note the double quotes.

Nope, no matter what you do, qw() really splits on whitespace.

  friday:~ $ perl -w
  @a = qw( "stuff", "more stuff", "even more stuff" );
  Possible attempt to separate words with commas at - line 1. <-- warning
  for (@a) { print "<$_>\n" }
  __END__

  <"stuff",>
  <"more>
  
  <"even>
  
  

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**I no longer need a publisher for my Perl Regex book :)**




Re: qw

2001-05-30 Thread Michael Fowler

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?

perldoc perlop:
   qw/STRING/
   Returns a list of the words extracted out of
   STRING, using embedded whitespace as the word
   delimiters.  It is exactly equivalent to

   split(' ', q/STRING/);


In this case, qw is being misused.  The code there is equivalent to:

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

What was probably intended is the equivalent of:

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

In which case the qw should just be dropped, the quoting is sufficient.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--



RE: qw

2001-05-30 Thread Larry Shatzer

Here is the documentation on it. 
( http://www.perldoc.com/perl5.6/pod/perlop.html#qw%2fSTRING%2f )

qw/STRING/ 
Evaluates to a list of the words extracted out of STRING, using embedded
whitespace as the word delimiters. It can be understood as being roughly
equivalent to:

split(' ', q/STRING/);
the difference being that it generates a real list at compile time. So this
expression:

qw(foo bar baz)
is semantically equivalent to the list:

'foo', 'bar', 'baz'
Some frequently seen examples:

use POSIX qw( setlocale localeconv )
@EXPORT = qw( foo bar baz );
A common mistake is to try to separate the words with comma or to put
comments into a multi-line qw-string. For this reason, the use warnings
pragma and the -w switch (that is, the $^W variable) produces warnings if
the STRING contains the "," or the "#" character.


> -Original Message-
> From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 30, 2001 1:39 PM
> To: [EMAIL PROTECTED]
> Subject: qw
> 
> 
> 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?
> 
> thanks, nichole
> 



RE: qw

2001-05-30 Thread Jeffrey Goff

It's a shortcut for assigning words to an array. That statement would return
an array that looks roughly like this:

('"stuff",', '"more stuff",', '"even more stuff"') # Note the double quotes.

Something like ("stuff","more stuff","even more stuff"); # was likely
intended, without qw().

Search for 'qw/STRING/' in perlop perldoc for more information.

-Original Message-
From: Nichole Bialczyk [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 4:39 PM
To: [EMAIL PROTECTED]
Subject: qw


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?

thanks, nichole