in reply to Non-greedy substitution
Just because I've never seen 'reductions' used before :)
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11162727 use warnings; use List::Util qw( reductions ); use Data::Dump 'dd'; dd map s/.*\K,/ and/r, reductions { "$a, $b" } 'A'..'Z';
Outputs:
( "A", "A and B", "A, B and C", "A, B, C and D", "A, B, C, D and E", "A, B, C, D, E and F", "A, B, C, D, E, F and G", "A, B, C, D, E, F, G and H", "A, B, C, D, E, F, G, H and I", "A, B, C, D, E, F, G, H, I and J", "A, B, C, D, E, F, G, H, I, J and K", "A, B, C, D, E, F, G, H, I, J, K and L", "A, B, C, D, E, F, G, H, I, J, K, L and M", "A, B, C, D, E, F, G, H, I, J, K, L, M and N", "A, B, C, D, E, F, G, H, I, J, K, L, M, N and O", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O and P", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P and Q", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q and R", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R and S", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S and T", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T and U", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U and V +", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V an +d W", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W + and X", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W +, X and Y", "A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W +, X, Y and Z", )
|
---|