l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
August 5: Social gathering
Next Installfest:
TBD
Latest News:
Jul. 4: July, August and September: Security, Photography and Programming for Kids
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.

	#!/usr/bin/ruby
	%w[Amador Calaveras El\ Dorado].each do |i|
		puts i
	end

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:
<http://hajhouse.org/hajhouse.asc>.

Attachment: pgp00026.pgp
Description: PGP signature



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
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:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.