Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: indexing in strings

by AnomalousMonk (Archbishop)
on Nov 24, 2012 at 15:59 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-18 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found