Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Matches 1

Status
Not open for further replies.

MinniePerl

Technical User
Apr 19, 2001
7
US
I'm bringing data in and substituting all s with xx. That works. How do I count the number of matches made and print that number?
@matches=....
$howMany=@matches
print $howMany
Am i going the right direction? Where is this inserted in my program? Thanks in advance for any help. Especially stillflame.



open (OLDFILE, &quot;<a:\\program1.txt&quot;); #retrieve data
@databack=<OLDFILE>; #assigns to array
close(OLDFILE); #closes



foreach (@databack)
{ #creates foreach loop, so each array is split
#and subs are made

($item, $itemprice, $itemnumber, $totalprice)=(/, /,); #splits data
s/s/xx/ig; #subs all s with xx


}

print @databack;




<STDIN>;

 
an unrelated problem - you're doing this: &quot;s/s/xx/ig&quot; after you assign the different pieces, which means that the pieces will not have received the changes the substitution made. it may be that you copied an incompete version of your code, but if not, and you want the variables to be affected, just switch that line with the one before it so that ($item, etc.) will have the substitutions done to them.

you are right on how to get an array's length, or you could be extra explicit and say &quot;scalar(@array)&quot; to get the same results. as for printing it, you can do that anytime you need that number. &quot;print scalar(@array);&quot; wait till after the searching is done so that the array is full, then just do it. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top