473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

collect and count letter strings

Hi
I have difficult undersating this problem

Read data from a I/P file.Ignore all lines that start with the literal string given as a command line argument. Otherwise, collect and count the letter strings, case
independently.

If the literal string is "foo" and a line starts
with "foo", ignore it. If a line does NOT start with foo
then the letter strings on it get counted (which might add to counts
from previous lines).

This is what i tried.I read the all the lines from file and ignored the lines starting with"foo".Rest of the part(collect and count the letter strings) I am not getting it.If any of u explain me I'll start working on that part of code.


Thank you
Mythili
May 4 '07 #1
5 2942
KevinADC
4,059 Expert 2GB
lets see your current code.
May 4 '07 #2
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. die:"Usage:$o infile outfile a string\n" if @ARGV!=3;
  3.  
  4. open(INFILE,"$ARGV[0]") || die"Cannot open infile!\n";
  5. open(OUTFILE,">$ARGV[1]") || die"Cannot open infile!\n";
  6.  
  7. foreach (<INFILE>) {
  8.     chomp;
  9.     $astring = @ARGV[2];
  10.     if ($_ !~ m/^($astring)/i) {
  11.         @words = $_;
  12.         #push(@all_lines,@words)
  13.     }
  14.     else{
  15.         @nowords=$_;
  16.     }
  17.     # print "@words\n";
  18.  
@words contains array of lines not starting with "this".
Next how can I collect and count the letter strings?

-Mythili
May 4 '07 #3
KevinADC
4,059 Expert 2GB
OK, your code can use some improvements, but since this looks like school/class work I won't make any changes to your existing code. Here is a sort of generic way to count words (or letter strings I guess) in a line, or array of lines:

Expand|Select|Wrap|Line Numbers
  1. @all_lines = ('foo bar baz','this is a test','a word');
  2. foreach $line (@all_lines) {
  3.    $count++  while $line =~ /\w+/g;
  4. }    
  5. print $count;
see if you can work that into your existing code.
May 4 '07 #4
KevinADC
4,059 Expert 2GB
more useful information:

http://perldoc.perl.org/perlfaq4.html
May 4 '07 #5
Thanks for dode.I'll work on it.

-Myhtili
May 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ntg85 | last post by:
Can you use variables in string.count or string.find? I tried, and IDLE gives me errors. Here's the code: while list: print letter = raw_input("What letter? ") string.lower(letter) guess =...
4
by: vertigo | last post by:
Hello How can i change big letter to small letter ? When i tried char=char+32 i received error that can not add int to sring. Thanx Michal
1
by: Paul Rowe | last post by:
Hi "You" I have two collection types declared at the SQL level. 1. Do you know of any known bugs with the BULK COLLECT clause used with the TABLE operator? I have a situation now where I am...
2
by: venkata | last post by:
hi I have a situation like this a field in a table has the following values of capacitors c1,c2,c5-c10 can I count the number of so that I get the result as 8 if so please help me...
7
by: Micheal Artindale | last post by:
I am looking at creating list of letter combinations. letters a-h 6 letters per combination letter can repeat its self in the combination, but not next to its self and, a series of letter can...
16
by: LP | last post by:
Hi, Considering code below. Will it make GC to actually collect. One application creates new instances of a class from 3rd party assembly in a loop (it has to). That class doesn't have .Dispose or...
5
by: Mrinal Kamboj | last post by:
Hi , Any pointers when it's absolute necessary to use it . Does it has a blocking effect on the code , as GC per se is undeterministic . what if GC.collect is followed in next line by...
10
by: Phil Stanton | last post by:
I am trying to count the fields in a queryDef in an external database. If I run this in the actaal database I get Fields.count = 6 correctly Private Sub ObjectName_DblClick(Cancel As Integer) ...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.