[thelist] Perl string help

Eduardo Kienetz eduardok at gmail.com
Tue Feb 13 05:05:26 CST 2007


On 2/13/07, Amy Johnson <amy at rocky-hills.com> wrote:
> Can anyone help me with a Perl string function?  I need to take the text
> from a textarea and split the string at the last blank space before 250
> characters.  So if I have a 1000 character string, it would be cut into
> about 4 or 5 strings at spaces between words.
>
> Any Perl gurus out there?
>
> Thanks,
> Amy

Amy, I'm not a Perl guru, but I'd basically use this in a loop so that
I keep reading the next 30 (in your case it's 250) characters.

#!/usr/bin/perl
use strict;
use warnings;

my $string = 'Eduardo Bacchi Kienetz lives in Santa Maria, Rio Grande
do Sul, Brazil.';
my $piece =  substr $string, 0, 30;
my $beforespace = substr $piece, 0, rindex($piece,' ');
print $beforespace . "\n";

-- 
Eduardo  Bacchi Kienetz
LPI Certified - Level 2
http://www.noticiaslinux.com.br/eduardo/



More information about the thelist mailing list