for this i have remove lines greater than 2 in $textTo extract just 2 lines, you can do $top2 = $text =~ /^(.*\n.*\n)/;
You can avoid unnecessary work in Text::Wrap if you limit the string you submit to it to a bit over the absolute maximum length of 2 lines together (your text says 140 characters, indeed a bit over 2x60 + 2 for the newlines), because the rest will be cut off anyway.
my $smstext = "This sentence will have more than 120 characters and i +want to truncate this string into two lines containing 60 characters +each and ignore characters above 140 in length" ; use Text::Wrap; local $Text::Wrap::columns = 60; my($text) = wrap('', '', substr($smstext, 0, 140)) =~ /^(.*\n.*\n)/; print $text; __END__ Output: This sentence will have more than 120 characters and i want to truncate this string into two lines containing 60
In reply to Re^3: Breaking String
by bart
in thread Breaking String
by harishnuti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |