Can the Repetition Operator Be Nested?

M

MES

I want to nest the repetition operator. Here is something like what I
want

print ("This " x 3 . "That \n") x 2;

This does not work because of the list context on the left hand side
of the x operator. Is there a way to do this?

Thanks
 
D

Darren Dunham

MES said:
I want to nest the repetition operator. Here is something like what I
want
print ("This " x 3 . "That \n") x 2;
This does not work because of the list context on the left hand side
of the x operator. Is there a way to do this?

Did you use -w and see that the parentheses are being interpreted as the
limit of the arguments to print?

print (("This " x 3 . "That \n") x 2);
 
D

David K. Wall

Darren Dunham said:
Did you use -w and see that the parentheses are being interpreted
as the limit of the arguments to print?

print (("This " x 3 . "That \n") x 2);

Or even:

print +("This " x 3 . "That \n") x 2;
 
M

MES

Thanks for the suggestions.

I used the -w flag but misinterpreted the error message. I also
slightly misrepresented the problem. I should have used printf instead
of print. What I want to do is build a format string. This prints out
the format string I expect

print (("This %s" x 2 . "\n") x 2);

But this does not produce the results I expect from printf

printf (("This %s" x 2 . "\n") x 2, "one", "two", "three", "four");

I suspect that the second copy of the format string is being supplied
as the argument for the first %s. "one" is supplied as the argument
for the second %s. The remaining supplied arguments are discarded
because the end of the format string has been reached.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top