[vox-tech] perl: quoting strings with spaces

Henry House vox-tech@lists.lugod.org
Sun, 22 Jun 2003 23:52:26 -0700


--+HP7ph2BbKc20aGI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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?
>=20
> You don't.
>=20
> >   foreach my $county (qw/Amador Calaveras 'El Dorado' Humboldt Lake Teh=
ama Trinity/)
>=20
> You could do something similar to this:
> =3D=3D=3D
> foreach (split ",",=20
>                '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.

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


--+HP7ph2BbKc20aGI
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD4DBQE+9qOqi3lu92AVGcIRAlx2AJ4kn3OKW/UU63Y+3pud12MPXWKndQCXeQbf
0QgGmPCQCDWLtPMtYZFUOA==
=zVNs
-----END PGP SIGNATURE-----

--+HP7ph2BbKc20aGI--