in reply to Splitting a string into words
#!/usr/bin/perl my $max_str_len = 12; my $string = "This is a test message"; $string =~ tr/ / /s; $string =~ s/^\s*//; $string =~ /(.{0,$max_str_len})(\s|$)/; my $trunc_string = $1; my @words = split /\s+/, $trunc_string; print "Word: ", $_, "\n" foreach @words;
|
|---|