From: Dominik Honnef Date: 2009-03-04T00:50:40+09:00 Subject: Re: expanding environment variable --gMR3gsNFwZpnI/Ts Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On [Wed, 04.03.2009 00:46], Brian Candler wrote: > Dominik Honnef wrote: > > On [Tue, 03.03.2009 23:58], Daniel Schoch wrote: > >> > constants like __FILE__ or simply global variables? > >> s =3D "x/test/y.z" > >>=20 > >>=20 > > | >>> DIR=3Dx FILE=3Dy.z irb > > | >> s =3D "$DIR/test/$FILE".gsub(/\$\w+/) {|m| ENV[m[1..-1]]} > > | =3D> "x/test/y.z" > >=20 > > Thats how I would do it. >=20 > Or: s =3D "$DIR/test/$FILE".gsub(/\$(\w+)/) { ENV[$1] } Probably depends on whether you like global variables or not. It is definitely shorter/more readable and I actually didn't know if gsub sets $1.=20 --=20 Dominik Honnef dominikho@gmx.net --gMR3gsNFwZpnI/Ts Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmtUhwACgkQePZ2jI1LDtd4cgCgpCKjqIT4iNAK3UsWHWQ2wS0q ZocAnAkDUUc8lnX7FgCDuko/m5ng5H9l =Ko/a -----END PGP SIGNATURE----- --gMR3gsNFwZpnI/Ts--