Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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";


Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772404]
and a soft breeze sighs...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-05-23 18:53 GMT
Find Nodes?
    Voting Booth?