in reply to sprintf and arrays of unknown (in advance) length
When dealing with lists and particularly intermediate lists in map/grep chains, it's sometimes difficult (or even impossible?) to know the number of list elements at runtime. This can be handled with yet another map expression:
This could be handled with an explicit intermediate array, but it's arguably more awkward:c:\@Work\Perl\monks>perl -wMstrict -le "print map sprintf(q{`%s' }, $_), grep m{ \A [aeiou] }xms, qw(elements comprising this list unknown in advance) ; " `elements' `unknown' `in' `advance'
(This doesn't reveal any new-found capability of sprintf, but that's life.)c:\@Work\Perl\monks>perl -wMstrict -le "printf do { my @elems = grep m{ \A [aeiou] }xms, qw(elements within this list unknown in advance) ; qq/@{[ q{`%s' } x @elems ]}/, @elems; }; " `elements' `unknown' `in' `advance'
Give a man a fish: <%-{-{-{-<
|
|---|