#!/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;
In reply to Re: Splitting a string into words
by Transient
in thread Splitting a string into words
by webchalkboard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |