One liner to produce string of n '?'s separated by commas ... ?

R

Richard Gration

Anyone for golf?

I can't think of anything shorter

$n = 10;
$vals = join ',', split //,'?' x $n;

In case anyone was wondering, this _is_ SQL related ;-)
 
J

Jonas Nilsson

Richard Gration said:
I can't think of anything shorter

$n = 10;
$vals = join ',', split //,'?' x $n;

How about:
$n=10;
chop($vals = '?,' x $n);

/jN
 
P

Paul Lalli

Richard Gration said:
Anyone for golf?

I can't think of anything shorter

$n = 10;
$vals = join ',', split //,'?' x $n;

Why bother creating a string only to spilt it?
$vals = join ',', ('?')x10;

Paul Lalli
 
R

Richard Gration

Why bother creating a string only to spilt it?

Well, that's kinda what prompted me to ask :)
$vals = join ',', ('?')x10;

The idea of using ('?') x 10 never occured to me. My mind did not suggest
it as valid syntax. Excuse me while I read perlop ...

Cheers
R
 
T

Tad McClellan

Richard Gration said:
I can't think of anything shorter

$n = 10;
$vals = join ',', split //,'?' x $n;


{ local $" = ',';
$vals = "@{[ ('?') x $n ]}";
}
 
R

Richard Gration

Anyone for golf?
I can't think of anything shorter

$n = 10;
$vals = join ',', split //,'?' x $n;
In case anyone was wondering, this _is_ SQL related ;-)

Such creativity :)

I think I will use Paul's solution. Cheers all
 
A

Anno Siegel

Abigail said:
Richard Gration ([email protected]) wrote on MMMMLXI September MCMXCIII
in <URL:"" Anyone for golf?
""
"" I can't think of anything shorter
""
"" $n = 10;
"" $vals = join ',', split //,'?' x $n;
""
"" In case anyone was wondering, this _is_ SQL related ;-)


$vals=("?,"x9)."?";

Short, but no good for $n == 0.

Anno
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top