
davorg
Thaumaturge
/ Moderator
Aug 12, 2005, 5:15 AM
Views: 2624
|
|
Re: [upyeronson] Counting Characters at at time.
|
|
|
Well, I'm not really sure how my previous message could have helped you as you seem to have completely ignored my code when writing yours :) So, what you actually seem to want to so is to pull data from a file, one word at a time until the next word would take you over 200 characters. Which is a completely different problem.
my $max_len = 200; my $string = ''; while (<FILE>) { foreach my $word (split) { if (length($string) + length($word) + 1 > $max_len) { # stop there last; } else { $string .= " $word"; } } } And, of course, this has nothing to do with regexes so it's in completely the wrong section of this site :) -- Dave Cross, Perl Hacker, Trainer and Writer http://www.dave.org.uk/ Get more help at Perl Monks
(This post was edited by davorg on Aug 12, 2005, 5:16 AM)
|