Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Here would be where the magic should happen, but it doesn't:#!/usr/bin/perl my $str2 = "Be careful what you wish for you just might get it ------- +--------test-----------results----------."; my @words = split(/\b/, $str2); my $longestwordlength = 30; my $longestword; foreach my $word (split(/\s+/, $str2)) { if (length($word) > $longestwordlength) { $longestword = $word; print "\n$longestword\n\n"; } }
Thanks for looking!(my $break2 = $str2)=~ s/(length($str2)>30)/$1\n/mg; print "\n$break2\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the largest word in a string help!
by moritz (Cardinal) on Dec 12, 2011 at 16:11 UTC | |
|
Re: Finding the largest word in a string help!
by Anonymous Monk on Dec 12, 2011 at 16:20 UTC | |
by Anonymous Monk on Dec 12, 2011 at 16:49 UTC | |
by Anonymous Monk on Dec 13, 2011 at 09:24 UTC | |
by TJPride (Pilgrim) on Dec 12, 2011 at 19:08 UTC | |
|
Re: Finding the largest word in a string help!
by TJPride (Pilgrim) on Dec 12, 2011 at 19:12 UTC |