Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Can we "grow" a string?

by citromatik (Curate)
on Jun 17, 2009 at 14:12 UTC ( #772404=note: print w/ replies, xml ) Need Help??


in reply to Re: Can we "grow" a string?
in thread Can we "grow" a string?

use strict; use warnings; use List::Util qw/min/; my $str = "ABCDEFGHIJKLMNOP"; my $seed = "FGH"; my $length = 7; my $r_lim = 2; my $l_lim = 1; my $slen = length $seed; my $ipos = index $str,$seed; my $lexpand = $slen < $length ? ($length - $slen)/2 : 0; $lexpand = min ($ipos, $l_lim, $lexpand); my $rexpand = $length - $slen - $lexpand; $rexpand = $r_lim < $rexpand ? $r_lim : $rexpand; print +(substr $str,($ipos - $lexpand),($lexpand + $slen + $rexpand)), +"\n";

citromatik


Comment on Re^2: Can we "grow" a string?
Download Code
Re^3: Can we "grow" a string?
by Anonymous Monk on Jun 17, 2009 at 15:29 UTC
    Thank you very much for your time!
Re^3: Can we "grow" a string?
by Anonymous Monk on Jun 28, 2009 at 15:10 UTC
    Well, I have been dealing with this problem quite some days now, and it works OK...
    Except something I found out today:
    Both in the initial code and in this one, there is a bug and I don't know how to deal with it:
    Check for instance the initial code you provided citromatik:
    If the substring is NO, the final output is KLMNOP, that is, it doesn't take J as well so as to become 7, which is the wanted final length.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2015-07-02 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls