Re: Counting the same word
i think this will work, but don't complain if it doesn't 'cos im tired. ok? #!/usr/bin/perl $count = 0; while (FILE) { if (m/california/) { $count++; } } print california: $count\n; On Tue, Sep 17, 2002 at 08:42:57 -0700, ANIDIL RAJENDRAN wrote: Hi, I want to count the number of times a particular word occured in a file. Though the following script is working, is it possible to shorten it? -- open (FILE,C:\\proj\\order\.txt) or die cannot open file: $!; %seen = (); while (FILE) { while ( /(\w['\w-]*)/g) { $seen{lc $1}++; } } print california: . $seen{california}.\n; -- Mat Harris OpenGPG Public Key ID: CC14DD34 [EMAIL PROTECTED]matthewh.genestate.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Counting the same word
nope that only counts the word once per line.. if the word was in the line twice it would only count it once. -Original Message- From: Mat Harris [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 17, 2002 12:06 PM To: ANIDIL RAJENDRAN Cc: [EMAIL PROTECTED] Subject: Re: Counting the same word i think this will work, but don't complain if it doesn't 'cos im tired. ok? #!/usr/bin/perl $count = 0; while (FILE) { if (m/california/) { $count++; } } print california: $count\n; The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting the same word
sorry, i meant this: #!/usr/bin/perl $count = 0; while (FILE) { if (m/california/g) { $count++; } } print california: $count\n; On Tue, Sep 17, 2002 at 12:08:03 -0400, Nikola Janceski wrote: nope that only counts the word once per line.. if the word was in the line twice it would only count it once. -Original Message- From: Mat Harris [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 17, 2002 12:06 PM To: ANIDIL RAJENDRAN Cc: [EMAIL PROTECTED] Subject: Re: Counting the same word i think this will work, but don't complain if it doesn't 'cos im tired. ok? #!/usr/bin/perl $count = 0; while (FILE) { if (m/california/) { $count++; } } print california: $count\n; The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- Mat Harris OpenGPG Public Key ID: CC14DD34 [EMAIL PROTECTED]matthewh.genestate.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Counting the same word
Are you only looking for 'california' (case-sensitive?) ? if so: open (FILE,C:\\proj\\order\.txt) or die cannot open file: $!; %seen = (); while (FILE) { $count += s/california//g; ## substitute returns number of subs (m// doesn't) } print california: $count\n; -Original Message- From: ANIDIL RAJENDRAN [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 17, 2002 11:43 AM To: [EMAIL PROTECTED] Subject: Counting the same word Hi, I want to count the number of times a particular word occured in a file. Though the following script is working, is it possible to shorten it? The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting the same word
It depends on what you mean by word I would assume you could do something like %seen = (); while( FILE ) { $seen{lc $_}++ for( split /\s+/ ); } - Original Message - From: ANIDIL RAJENDRAN [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, September 17, 2002 11:42 AM Subject: Counting the same word Hi, I want to count the number of times a particular word occured in a file. Though the following script is working, is it possible to shorten it? -- open (FILE,C:\\proj\\order\.txt) or die cannot open file: $!; %seen = (); while (FILE) { while ( /(\w['\w-]*)/g) { $seen{lc $1}++; } } print california: . $seen{california}.\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]