Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: indexing in strings

by AnomalousMonk (Abbot)
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.


Comment on Re: indexing in strings
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005387]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-09-16 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (4 votes), past polls