473,412 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

writing to unknown number of files

2
Hi,

I have a problem.

I need to open unknown number of files for writing.
In order to solve the problem I tried to open files in an array,
where each node in the array is a pointer to a file.
I succeed in opening the files and close all the files,
but I can't write to them.

Please help me!

Thanks,
Rotem.

This is the code:
-----------------------------------
open the files (works):
----------------------------------
while ($currFile < $totalFiles)
{
# open data file
open($dataFilesList[$currFile], ">$currFile");
$currFile++;
}
--------------------------------------------------
write to the files (doesn't work):
--------------------------------------------------
while ($currFile < $totalFiles)
{
print $dataFilesList[$currFile] ("bla bla");
$currFile++;
}

This is the error:
Not a CODE reference at ./script.pl line 263, <INPUT_FILE> line 1

------------------------------------
close the files (works):
------------------------------------
while ($currFile < $totalFiles)
{
# close data file
close($dataFilesList[$currFile])
$currFile++;
}
Jan 25 '07 #1
5 1421
KevinADC
4,059 Expert 2GB
Look into using the IO::File module for this task.
Jan 25 '07 #2
you are using $currFile and $totalFiles as numbers:
Expand|Select|Wrap|Line Numbers
  1. while ($currFile < $totalFiles)
  2. ...
  3. $currFile++
  4. ...
But, when opening files
Expand|Select|Wrap|Line Numbers
  1. open($dataFilesList[$currFile], ">$currFile");
you use $currFile as a filename.

This can't work.

Greetz, Doc
Jan 26 '07 #3
KevinADC
4,059 Expert 2GB
you are using $currFile and $totalFiles as numbers:


you use $currFile as a filename.

This can't work.

Greetz, Doc
It could work, $currFile is just the index number of the array element $dataFilesList[$currFile]. If the array element were a proper filehandle then it could work. It's just not necessary to do it that way.
Jan 26 '07 #4
rotems
2
Hi All,
Thanks for your suggestions.
This was the solution I found:

while ($currFile < $totalFiles)
{
$file=$dataFilesList[$currFile];
print $file ("bla bla");
$currFile++;
}

Regards,
Rotem.
Jan 28 '07 #5
KevinADC
4,059 Expert 2GB
this doesn't work?

Expand|Select|Wrap|Line Numbers
  1. while ($currFile < $totalFiles)
  2. {
  3. print $dataFilesList[$currFile] ("bla bla");
  4. $currFile++;
  5. }
Jan 29 '07 #6

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

Similar topics

10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
2
by: John Baker | last post by:
Hi: I have two systems, one a W98 and the other XP Home. I have Access 2000 installed on both, and have run into a difference in the way the two behave. I have a table on which I wish to reset...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
0
by: bohuge | last post by:
Hey! At the time being I'm working on a backup solution for a Qtek9090 pocketpc, which should be able to find and backup outlook data to a server, local files, messages and contact from the sim...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
2
by: | last post by:
Hi, I have an idea that I want to write to many (qty unknown untill run time but in the order of 5) text files as my application runs. They're log files dealing with different aspects of the...
3
by: koutoo | last post by:
I have a code that writes to 2 seperate files. I keep getting a "list index out of range" error. The strange part is that when checking the files that I'm writing too, the script has already...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
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,...
0
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...

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.