[asterisk-users] Passing literals with commas to subroutine [SOLVED]
A J Stiles
asterisk_list at earthshod.co.uk
Thu Dec 11 06:40:58 CST 2014
On Tuesday 09 Dec 2014, Daniel Gonzalez wrote:
> Hi,
>
> Let's say I do:
>
> Set(data=xxx,yyy)
> Gosub(my-sub,s,1(${data}))
>
> My subroutine will only receive "xxx" for ARG1. How can I pass a literal
> with a comma to a single argument in a subroutine?
>
> (The point is: when calling the subroutine I do not know if the variable
> has a comma or not.)
O.K. I've managed to set myself up a temporary Asterisk box, so I was able to
do some testing without risking bringing down a production server :) And I
have managed to put together a solution, if you can call it that.
If you put speech marks around the argument, like so:
Gosub(my-sub,s,1("${data}"))
then what actually comes through in ${ARG1} is
"xxx,yyy"
(complete with the speech marks). But at least that comma is protected. So
then within my-sub, you just need to evaluate ${ARG1:1:-1}, ${ARG2:1:-1} &c.
to strip off the first and last characters (skip one, show all but one).
It's a bit ugly -- but so is a lot of stuff written in the Dialplan. Just
because a language is Turing-complete, doesn't mean any code written in it is
going to be pretty. But you might be able to mitigate some of the ugliness
with comments (introduced with a semicolon in Dialplan, because the comment
mark is a valid "digit").
--
AJS
Note: Originating address only accepts e-mail from list! If replying off-
list, change address to asterisk1list at earthshod dot co dot uk .
More information about the asterisk-users
mailing list