[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Perl-like strings...?
- From: "Andy Stark" <AStark@...>
- Date: Mon, 09 Oct 2006 11:14:38 +0100
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.
#####################################################################################