这个子程序究竟做了什么?

Wil*_*ill 4 perl coding-style

我有一段历史Perl代码具有以下功能:

sub binds { join(",", ("?")x$_[0]) }
Run Code Online (Sandbox Code Playgroud)

稍后用binds(4)等等来调用它.从我所知道的是加入?s和,s但是我已经迷失了确切的方式,我也不理解这x$_[0]部分.

mae*_*ics 10

此函数将整数(比方说n)作为其第一个参数,并返回n由逗号分隔的问号字符串.以下是它如何分解:

sub binds {
  join(",", ("?") x $_[0]);
  #         ?     ? ????? the first argument to the subroutine.
  #         ?     ??? the repetition operator (think multiply).
  #         ???? a list containing only the string literal "?".
}
binds(4) # => "?,?,?,?"
Run Code Online (Sandbox Code Playgroud)

它可能是数据库接口的实用程序函数,用于创建指定数量的?占位符,这些占位符稍后将作为SQL语句的一部分绑定到某些特定值.