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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Can we "grow" a string?
by Anonymous Monk on Jun 17, 2009 at 15:29 UTC | |
Re^3: Can we "grow" a string?
by Anonymous Monk on Jun 28, 2009 at 15:10 UTC |
In Section
Seekers of Perl Wisdom