in reply to Re: Adding a TAB after a certain ammount of characters
in thread Adding a TAB after a certain ammount of characters
Attacking the insertions in reverse order from the right-hand side means you don't have to increment your position by one for each successive insertion. Swings and roundabouts really but sometimes a useful technique.
$ perl -Mstrict -Mwarnings -E ' > my $text = > q{2013020400000000006810083610022013068100200220130688000200494}; > my @offs = ( 17, 6, 31, 3, 3 ); > my @cums = ( 0 ); > push @cums, $_ + $cums[ -1 ] for @offs; > substr $text, $_, 0, q{-} for reverse @cums[ 1 .. $#cums ]; > say $text;' 20130204000000000-068100-8361002201306810020022013068800-020-049-4
Here's the code without the PS2 prompt for easier copy'n'paste, as requested by /msg in respect of another post.
perl -Mstrict -Mwarnings -E ' my $text = q{2013020400000000006810083610022013068100200220130688000200494}; my @offs = ( 17, 6, 31, 3, 3 ); my @cums = ( 0 ); push @cums, $_ + $cums[ -1 ] for @offs; substr $text, $_, 0, q{-} for reverse @cums[ 1 .. $#cums ]; say $text;'
I hope this is of interest.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Adding a TAB after a certain ammount of characters
by biancoari (Initiate) on Apr 17, 2013 at 03:11 UTC | |
by johngg (Canon) on Apr 17, 2013 at 11:15 UTC | |
by biancoari (Initiate) on Apr 17, 2013 at 12:09 UTC | |
by hdb (Monsignor) on Apr 17, 2013 at 12:11 UTC | |
by choroba (Cardinal) on Apr 17, 2013 at 12:33 UTC | |
by biancoari (Initiate) on Apr 17, 2013 at 16:04 UTC | |
| |
by AnomalousMonk (Archbishop) on Apr 17, 2013 at 11:19 UTC |