l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jun 23 10:45

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] perl: quoting strings with spaces
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] perl: quoting strings with spaces

On Sun, Jun 22, 2003 at 12:08:53AM -0400, Mike Simons wrote:
> On Sat, Jun 21, 2003 at 05:22:17PM -0700, Peter Jay Salzman wrote:
> > when using a quoting operator like qw and friends, how does one one
> > quote a string with spaces?
> You don't.
> >   foreach my $county (qw/Amador Calaveras 'El Dorado' Humboldt Lake Tehama Trinity/)
> You could do something similar to this:
> ===
> foreach (split ",", 
>                'Amador,Calaveras,El Dorado,Humboldt,Lake Tehama,Trinity') {
>   print "$_\n";
> }

Also possible:

	foreach my $county ('Amador', 'Calaveras', 'El Dorado', ...) {
		<perform actions>

but that does not avoid quotes and commas, the point of the qw// operator.
Escaping the pace using \ does not work, either :-(.

At the risk of being annoying, I will mention that the analogous operator in
Ruby does support just that.

	%w[Amador Calaveras El\ Dorado].each do |i|
		puts i

iterates over three array elements as expected, not four.

Henry House
The unintelligible text that may follow is a digital signature. 
See <http://hajhouse.org/pgp> for information.  My OpenPGP key:

Attachment: pgp00026.pgp
Description: PGP signature

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.