![]() |
| ||
| count characters in a string This code counts number of characters in a single line how can I make it count(give total X Y Z) it in multiple lines seperated by ">" while(<IN>) { |
| ||
| Re: count characters in a string open(IN, "readme.txt") || die "ERROR: $!"; # readme.txt katharnakh. |
| ||
| Re: count characters in a string This is what I am looking for |
| ||
| Re: count characters in a string Hi, since, X, Y and Z are repeating after every line having '>', make line having '>' as initial key in hash, and then add keys(X, Y, Z) and values. open(IN, "readme.txt") || die "ERROR: $!";Note: Please dont post your queries to private message, the forum is provided for that only, getting help. katharnakh |
| ||
| Re: count characters in a string Thanks :) |
| ||
| Re: count characters in a string I have been playing with this. I have tried updating it to count words. When I update the split to /\s+/ I receive an error for an unitialized hash value. How would I correct it? I tried by changing the elsif line to not include the X,Y and Z argument. |
| ||
| Re: count characters in a string post your code and some sample data. |
| ||
| Re: count characters in a string Below is the code I am working with: 1. use strict; Text for the sample is: ======Retirement Plan Fundamentals Part I The objective of the Retirement Plan Fundamentals, Parts I and II, is to give an individual beginning a career as a retirement plan professional a general background in qualified plans as a first step toward meeting the challenges of the profession. =====Retirement Plan Fundamentals Part III Retirement Plan Fundamentals Part III (RPF-3) covers plan administration, including census collection, benefit allocations and coverage and nondiscrimination testing. This course emphasizes daily valuation recordkeeping but includes discussions of balance-forward plans and conversions. I am looking to count the words in each section seperately but reported in one output. Thanks |
| ||
| Re: count characters in a string open(IN, "readme.txt") || die "ERROR: $!"; You should use a regular expression to check whether line is having a character '=', and everything else is same. Also you need to one more line to inner foreach loop to output to a file. sample output: ======Retirement Plan Fundamentals Part I: plans: 1 background: 1 first: 1 individual: 1 ... =====Retirement Plan Fundamentals Part III: conversions.: 1 plans: 1 course: 1 allocations: 1 ... katharnakh. |
| ||
| Re: count characters in a string this might return false matches: if($line[0] =~ /=/) it would be better (I think judging by the sample data) to anchor it to the beginning of the string: if($line[0] =~ /^=/) at least that way you know it not somewhere else in the string. Might be better to just use the index() function though to avoid the unecessary overhead of a regexp. This is also not correct syntax: elsif ($line[0] =! /=/)
should be: elsif ($line[0] !~ /=/) |
| All times are GMT -4. The time now is 1:59 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC