473,626 Members | 3,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write to a file under appropriate block?

25 New Member
Hi,

I have a file which is in the following format:

This file is classify.txt
#######Alphabet s#########
.
.
.
#######Numbers# #########
.
.
.

In my perl program, I initialize an array which has both numbers and alphabets.
I open the classify.txt file for writing.

1. The program will check each and every element in the array using the foreach loop.

2. It has to then write to this classify.txt file accordingly under either Alphabets or Numbers. [That is, if the element is a alphabet, it has to write under the #######Alphabet s######### and if it is a number, it has to write under the #######Numbers# ######### block in classify.txt file]

I have no problem with the first part.

Can someone please let me know how I can write to a file like the way I mentioned in [2].

I would appreciate your response.

Thanks,
Sangeetha
Jun 27 '07 #1
5 1416
KevinADC
4,059 Recognized Expert Specialist
Lets see what you have tried so far.
Jun 28 '07 #2
miller
1,089 Recognized Expert Top Contributor
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR
Jun 28 '07 #3
sangith
25 New Member
Thanks Miller for the useful advice. I totally agree. I am not a student.
Although I should'nt be lazy to think. Programming is a lot of fun only if I think and attempt the problem myself. That will also help me learn so much.
I will definitely post questions only if I face any difficulty in the middle.

Thanks.
Sangith
Jun 28 '07 #4
sangith
25 New Member
Lets see what you have tried so far.
Right now, I am reading the file into an array and then using Regex, I am trying to place the elements under appropriate sections. I am positive that I am going to finish this problem with my approach.

Thanks,
Sangith
Jun 28 '07 #5
KevinADC
4,059 Recognized Expert Specialist
Right now, I am reading the file into an array and then using Regex, I am trying to place the elements under appropriate sections. I am positive that I am going to finish this problem with my approach.

Thanks,
Sangith

Very good. If you get stuck ask a question, but please post the code you have written up to that point.

Regards,
Kevin
Jun 28 '07 #6

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

Similar topics

7
3019
by: Patrick Useldinger | last post by:
Hi, I think I found a bug in the write method of file objects. It seems as if before writing each block, a check was done in order to verifiy that there is enough space left for the *whole* file, not for the *remaining* data to be written. It happens both under 2.3 and 2.2.3. Any ideas?
3
12225
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in nonblocking mode in c++? I did something ugly like --- c/c++ mixture --- mkfifo( "testpipe", 777);
18
4875
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
8
3875
by: Roberto Rocco | last post by:
Hello, I have a struct and want to stream it to a file (binary). I cannot use because this is not supported under the Compact Framework. What is the best approach to use? Another question in this aspect: How to I retrieve the size of my stuct? SizeOf seems not to work on structs? Many thanks in advance, Roberto.
2
1997
by: rr | last post by:
Hi, i have to write a file composed of n packets of a given length. I need to write this file writing every packet when i get it, knowing its number and length. I mean: packet #0 -length 100 starting from position 1 packet #5 -length 100 starting from position 501 packet #3 -length 100 starting from position 301 ......and so on.
4
6852
by: welch | last post by:
while taking some rough disk performance measures on windows machines, and snooping with FileMon, i've noticed some odd behavior here's the little nul-writer i'm running: def writeTest(nBlocks, blockSize): """write nBlocks*blockSize nuls to a file""" f = open("writeTest.out", "wb") nulBlock = '\0'*blockSize while nBlocks: f.write(nulBlock)
3
3769
by: dnatzic | last post by:
// I have a block of code that runs okay but I need to write all the data to a file placing the appropriate label between each section of output. How would I do that?. import java.io.*; public class Ch5_PrExercise9 { static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); public static void main(String args) throws IOException
16
4679
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good) free hoster in Norway which doesn't use safe mode, running PHP 5.1.6 as the PHP info below shows ... Test it at: http://home.no.net/moldevbk/fopen-test/?mode=w (write - fails) http://home.no.net/moldevbk/fopen-test/?mode=a (append - ok)...
16
8936
by: vizzz | last post by:
Hi there, i need to find an hex pattern like 0x650A1010 in a binary file. i can make a small algorithm that fetch all the file for the match, but this file is huge, and i'm scared about performances. Is there any stl method for a fast search? Andrea
0
8262
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
8196
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
8701
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...
1
8364
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6122
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
5571
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
4090
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
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.