Re: New and having problems
- Posted by peterR May 18, 2016
- 1933 views
Hi Mollusk
It's probably easiest to answer this by copy-pasting from the depths of the manual:
Comments
Watch out for the following common mistake, in which the intention is to output all the characters in the third parameter but which ends up by only outputing the first character ...
include std/io.e sequence name="John Smith" printf(STDOUT, "My name is %s", name)
The output of this will be My name is J because each format specifier uses exactly one item from the values parameter. In this case we have only one specifier so it uses the first item in the values parameter, which is the character 'J'. To fix this situation, you must ensure that the first item in the values parameter is the entire text string and not just a character, so you need code this instead:
include std/io.e name="John Smith" printf(STDOUT, "My name is %s", {name})
Now, the third argument of printf() is a one-element sequence containing all the text to be formatted.
Also note that if there is only one format specifier then values can simply be an atom or integer.
Also, I think there's a problem with your for loop. It keeps overwriting the arguments instead of concatenating them (so the problem only shows up when you have more than one arg). For your system call you need a single sequence (a string). Initialise pkgargs to an empty string before the loop, and then concatenate it with the commands on each iteration (don't forget the space) - e.g. pkgargs = pkgargs & cmd[i] & " ", or even better, pkgargs &= cmd[i] & " ". PeterR
Edit: Fixed formatting for you. -Greg