Im sure there are a few other people that I know that will have different opions. But you could use code like this to find how many rows are in your file.
sub TotalRows {
open (FILE, "filename.data");
@rows =
;
close (FILE);
$Total = @rows;
return($Total);
}
$totalrows = &TotalRows;
So that gives you the amount of rows in your file. I think this will accomplish what you want to do
------------------
My Freeware Board
uh ahr, im a little confused about how knowing the amount of rows would help, ill try explaning in a little more detail:
if i had;
19|1|9/5/00
18|2|9/5/00
17|5|9/5/00
16|4|9/5/00
15|4|9/5/00
14|1|8/5/00
13|3|7/5/00
12|2|5/5/00
11|6|5/5/00
10|5|5/5/00
9|5|5/5/00
8|4|5/5/00
7|6|4/5/00
6|1|3/5/00
5|4|2/5/00
4|2|2/5/00
3|1|2/5/00
2|1|2/5/00
1|1|1/5/00
i would want my script to dismiss all of the lines except 19 (as that is the most recent post in column 1), 18 (most recent in 2), 13 (most recent in 3) 16 (most recent in 4), 17 (most recent in 5), 11 (most recent in 6)
i would then define those lines as something like:
($posted, $category, $date) = split(/|/,$line);
(well line 19 as $1date, 18 $2date, 13 $3date etc..)
therefore i would be looking for some type of script that would let me search from the top for the first 1 in the second column (in this case it is line 19) and use that line so i can then use that line to difine the 3rd column as $1date to use it as "last posted in" for column 1.
----------------------------
i could gain the same effect is i knew how to overwrite a file with a new one (or delete a file then replace it with one of the same name) however i presume that would use more sever processorage (i doubt it will be alot but i am using a UBB on netfirms so id rather use a very little as possible)
------------------
Please clean my floor
So ya want to read the first 10 lines of a file?? This should do it.
EG:
Then you can use a foreach statement to get the data from @line...
------------------
Da Wannabe Cannuck
Andy Tomaka
YaBB Developement Team
[email protected] http://www.yabb.org [This message has been edited by atom911 (edited September 13, 2000).]
Where in the world are you guys getting the information that he wants to count the number of lines in a file, or get the first X lines??
He wants to extract the record containing the highest number id (column [0]) for each category (column [1]).
I see six categorys. Meaning he wants the result set to have six entries. One for each category, and it's corresponding id#. What's so hard about understanding that?
I don't have time to work out the algorithm for it right now, so you guys give it your best.
--mark
------------------
Damn, I feel stupid. I got some homework to do, but I may throw something together tomorrow...
------------------
Da Wannabe Cannuck
Andy Tomaka
YaBB Developement Team
[email protected] http://www.yabb.org [This message has been edited by atom911 (edited September 13, 2000).]
Quick way:
Can definatly be done more elegantly (using map) but im too tired to bother trying,
--mark
------------------