in reply to Rewrite in a more compact way

Clearer I think?

my $str = sprintf 'CALL DB_PROC_FOO( %s )', join ',', ('?') x $n;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Rewrite in a more compact way
by wfsp (Abbot) on Nov 27, 2008 at 15:33 UTC
    I'd reach for sprintf too. But I'd put my one line on seven. Does that count? :-)
    my $str = sprintf( q{CALL DB_PROC_FOO(%s)}, join( q{,}, (q{?}) x $n, ), );
    I like to use parens in these cases to have something to pin the ; to. And if there are other joins, splits etc. it stops perl getting confused about where lists start and end.

      Well, it's in the eye of the beholder, (and I don't mean 'beauty' :), but that's just verbosity for it's own sake (IMO).

      The most that is required here (and only then if you insist on sticking with the limitations of 1970s VTs), is:

      my $str = sprintf( 'CALL DB_PROC_FOO(%s)', join ',', ( '?' ) x $n );

      I'd love to see the PBP justifiction for this absurd practice of always replacing simple string constants with verbose and confusing q{} constructs. (Damn! But has that book got a lot to answer for!).


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I'd love to see the PBP justifiction for this absurd practice of always replacing simple string constants with verbose and confusing q{} constructs.

        PBP doesn't actually recommend always replacing 'foo' with q{foo}.

        It does prefer

        • q{O'Reilly} over 'O\'Reilly',
        • q{'} over '\'',
        • q{} over '', and most controversially
        • q{,} over ','.