473,789 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return the number of records (rows) in a flat file db?

40 New Member
I am wanting to return the number of records (rows) in a flat file db.
My script is a resource kit library and each item has a catalog number ($catnumber), instead of the user having to remember the next catalog number to enter as they add a record, I want to be able to either show them the next number or have it as a value in a field on the form.

I just need to know how to return the total number of records (rows?) in the db as a number (plus 1..that would be their next catalog ($catnumber) number)

is it something to do with rec_count?

I tried:
open (DB, "< /full/path/db/db.txt") || die "cannot open full/path/db/db.txt: $!";
while (<DB>) {
($catnumber) = split(",");
}
But what I got was the value ($catnumber) of the LAST record they entered.

thanks
Jul 23 '07
10 4969
deppeler
40 New Member
I meant use append mode if all you want to do is write some more data to the end of the file, not use it to count the number of lines in the file. If you want to count the number of lines there is no need for an extra variable:

Expand|Select|Wrap|Line Numbers
  1. open (FILE, 'yourfile');
  2. while(<FILE>){
  3. $num_of_records = $.;
  4. }
  5. $num_of_records += 1; 
"+=" adds whatever value is on the right to the variable on the left in one step. So if there are 100 lines in the file, $num_of_records will equal 101.

Millers link was:

how do I count the number of lines in a file
Great thanks for all your help!

Paul
Jul 23 '07 #11

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

Similar topics

16
3014
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however lately I've been wanting to do more stuff with user accounts, and had been eying MySQL for over a year. Finally I've decided to start off small by converting the forum's account system to a MySQL database (and convert the rest later after I'm...
2
1987
by: AG | last post by:
I have a very big table with 20 million records DistinctProjectionKey which i join several times to different tables in this query. select distinct distinctprojectionkeyid,dpk.MarketID, dpk.Classificationid, dpk.DistributorID, dpk.ManufacturerID, dpk.LocationID, dpk.TimeID,P4.FACTOR as factor1,P3.FACTOR as factor2 ,P2.FACTOR as factor3,P1.FACTOR as factor4
19
81872
by: xixi | last post by:
i want to use sql query to open a resultset, say i want the cursor point to whatever position i start with by giving a row number , so is there anyway i can use the sql function to do that, so when the resultset return, the first row will be the absolute row dertermine by the row number
2
1867
by: Stuart Norris | last post by:
Dear Readers, I am developing an application that stores "messages" in array list and writes new entries to a disk file at the end. This file is used incase the user choses to restart the program. When the program is restarted the messages are replayed so the application knows where it is up to. I am not allowed to use a **database** I have been instructed to use a flat file. The application I am replacing does that.
2
4348
by: Mike Charney | last post by:
I have a table that is created using the TransferText method. The file being imported has column headings in it for the data, but the first few rows after the headings are blank. The program that is generating the flat file is putting them in and I can not remove them. I need to remove them from the access table. Does anyone know how would I do this?
2
1481
by: Vadim | last post by:
Hi! I imported some table (about 1500 records) using "LOAD DATA LOCAL INFILE..." (command line console). No warnings, no skipped, no deletes - all the recored are written to be imported. However, in MySQL Administrator UI tool I see completely different number in the "Rows" column. Making a SELECT query shows that the actual number of records in the table is the correct one (the same number as in text file table). Command line SHOW TABLE...
6
3979
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
0
6187
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on a template spreadsheet with a fixed number of columns to be "macro'd" bounded by data that changes in its number of rows. That is, the bounding data is imported to the spreadsheet before the calculated columns are run. But the rows of this data...
11
10003
by: JimN1 | last post by:
Hi, I am looking for an example to convert a flat text file with variable length records to a flat file with fixed length records. Does anyone have an example?
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.