Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: indexing in strings

by AnomalousMonk (Chancellor)
on Nov 24, 2012 at 15:59 UTC ( #1005387=note: print w/replies, xml ) Need Help??

in reply to indexing in strings

As others have remarked, I find the problem statement confusing. (In particular, these tired, old optics would have appreciated less eye-bezoggling example strings!) However, a couple of code examples that might help to define the problem:

>perl -wMstrict -le "my $big = 'xyzzyABCDfoobar'; my $small = 'ABCD'; ;; (my $padded = $big) =~ s{ \A (.*?) (\Q$small\E) (.*) } { 'o' x length($1) . $2 . 'i' x length($3) }xmse or die 'small substring not found'; print qq{'$big'}; print qq{'$padded'}; ;; $padded = ''; my $is = index $big, $small; die 'small substring not found' if $is < 0; my $op = $is; my $ip = length($big) - length($small) - $op; $padded = 'o' x $op . $small . 'i' x $ip; print qq{'$big'}; print qq{'$padded'}; " 'xyzzyABCDfoobar' 'oooooABCDiiiiii' 'xyzzyABCDfoobar' 'oooooABCDiiiiii'

Update: Added die on substitution failure in substitution example.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005387]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2018-03-20 14:51 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (254 votes). Check out past polls.