CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [upyeronson] Counting Characters at at time.: Edit Log



davorg
Thaumaturge / Moderator

Aug 12, 2005, 5:15 AM


Views: 5256
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.


Code
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)


Edit Log:
Post edited by davorg (Thaumaturge) on Aug 12, 2005, 5:16 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives