lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> disadvantage is that it is a lot more typing than the original concat
operation 

I was building on your "further refinement", though:

>A further refinement would be to allow non-numeric indices in the template
>and the table

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Andy Stark
Sent: 09 October 2006 11:15
To: Lua list
Subject: Re: Perl-like strings...?

Lua list <lua@bazar2.conectiva.com.br> on Monday, October 9, 2006 at 10:53
+0000 wrote:
>Or even
>	"Name $fname, Rank: $rankstr, Serial: $sernum" % {fname="Andy",
>rankstr="Captain", sernum=1234}
>
>which is closer to the original syntax suggestion.

I agree that this approach is more Perlish but the disadvantage is that it
is a lot more typing than the original concat operation:-

	str = "Name:" .. fname .. ", rankstr:" .. ", Serial: " .. sernum

...especially if your table index names/variable names are long - you
always have to type them twice.

If you use

	str = "Name: [1], Rank: [2], Serial: [3]" % {fname, rankstr, sernum}
	
...then it's still quite quick, but you avoid getting lost in a sea of
quotes and you can change the ordering of the interpolated values either
by changing the table or the format string, whichever is easier. The
$varname approach isn't quite as good from a maintenance point of view.

&.


############################################################################
#########
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal.
The Blackpool Sixth Form College.
############################################################################
#########