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
10 4922 KevinADC 4,059
Recognized Expert Specialist
by"rows" do you mean lines? $. is the input record line number variable. - open (FILE, 'yourfile');
-
while(<FILE>){
-
$num_of_records = $.;
-
}
-
print $num_of_records;
Thank you!
If I was to alter:
$num_of_records = $.;
to this:
$num_of_records = $. + 1;
would it give me the next line number?
I'm going to have this as an input value on a form.
thanks
KevinADC 4,059
Recognized Expert Specialist
Yes it would. But add one to $num_of_records after closing the file, not while reading the file.
If the file is being accessed and updated often the last line number may be out of date by the time it is used again. If you are just adding to the end of the file why not just open the file in append mode?
Yes it would. But add one to $num_of_records after closing the file, not while reading the file.
If the file is being accessed and updated often the last line number may be out of date by the time it is used again. If you are just adding to the end of the file why not just open the file in append mode?
As in:
open (FILE, 'yourfile');
while(<FILE>){
$num_of_records = $.;
}
$recn = $num_of_records = $. + 1;
What is append mode?
thanks
Would it be:
open (FILE, '>>yourfile');
while(<FILE>){
$num_of_records = $.;
}
$recn = $num_of_records = $. + 1;
I did the above (append) but it returned $recn a value of 1 instead of 383 (which is the number of records)
What did I do wrong?
thanks
Ok thanks
One question:
Is this append mode:
open (FILE, '>>yourfile');
while(<FILE>){
$num_of_records = $.;
}
$recn = $num_of_records = $. + 1;
and this not:
open (FILE, 'yourfile');
while(<FILE>){
$num_of_records = $.;
}
$recn = $num_of_records = $. + 1;
thanks
KevinADC 4,059
Recognized Expert Specialist
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: - open (FILE, 'yourfile');
-
while(<FILE>){
-
$num_of_records = $.;
-
}
-
$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
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: - open (FILE, 'yourfile');
-
while(<FILE>){
-
$num_of_records = $.;
-
}
-
$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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
by: kilter |
last post by:
Anyone know of a routine that will return the number of rows and
columns in a matrix?
|
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...
|
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?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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: 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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |