in reply to sprintf: using nested code

Try:

my $ordered_schema = sprintf( "%s%s", $header . "\n", sub { my $ordered_columns; for my $column (sort keys %columns) { $ordered_columns .= $columns{$column} . "\n"; } return $ordered_columns; }->(), );

Though this is simpler:

my $ordered_schema = join "\n", $header, map $columns{ $_ } sort keys +%columns;

You could also use:

my $ordered_schema = sprintf( "%s%s", $header . "\n", do { my $ordered_columns; for my $column (sort keys %columns) { $ordered_columns .= $columns{$column} . "\n"; } $ordered_columns; ## Update: return statement removed. Thanks +Choroba. }, );

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^2: sprintf: using nested code
by mhearse (Chaplain) on Sep 14, 2015 at 19:51 UTC
    Thanks. Exactly what I needed.