Was having fun with variations on
johngg's use of a lookahead (novel, at least to me; ++). Then took one version of OP's spec -- the 10 chars
AFTER each "47" -- as my target and came up with this (
awkward and ugly?, besmirched with globals; non-PBP) approach:
#!/usr/bin/perl
use 5.016;
use warnings;
# D:\_Perl_\PMonks\1053693.pl
my $str = q/471234xx3798375754712345678901234547zyxabcdefghjkl/;
my ($arr, @arr1, $arr1, $i);
my @arr = split /47/, $str;
for $arr ( @arr ) {
@arr1 = split //, $arr;
for $i (0 .. 9) {
no warnings 'uninitialized';
$arr1 .= $arr1[$i];
use warnings;
}
say "$arr1\n";
undef $arr1;
}
=head output:
1234xx3798
1234567890
zyxabcdefg
=cut
Would welcome suggestions for using this approach more elegantly (for the spec '10 char after "47"').
If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.