473,378 Members | 1,156 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,378 software developers and data experts.

File Handling - Read and Write Access

How do we open a file for both reading and writing in perl????
I found the following in the book Perl 5 by Example by David Medinets

open(FILE_HANDLE, +<FILENAME.EXT);
open(FILE_HANDLE, +>FILENAME.EXT);
open(FILE_HANDLE, +>>FILENAME.EXT);

Opens FILENAME.EXT for both input and output using FILE_HANDLE as the file handle.

But none of these seem to work..
Mar 27 '07 #1
2 2726
miller
1,089 Expert 1GB
Hi suruchimathur,

That's because you're missing your string quantifiers around the second argument. Read here:

perldoc open
perldoc perlfaq5 - How come when I open a file read-write it wipes it out?

You can actually read all of perlfaq5 for a lot of useful tips and informations

- Miller
Mar 27 '07 #2
KevinADC
4,059 Expert 2GB
I found the following in the book Perl 5 by Example by David Medinets
Thats actually a pretty good book but unfortunately it does contain a few errors and ommissions. Like David never mentions you have to quote the various open() options, and there were some other examples that were just wrong. It's too bad because that book is good otherwise.

Expand|Select|Wrap|Line Numbers
  1. open(FILE_HANDLE, "+<FILENAME.EXT");
  2. open(FILE_HANDLE, "+>FILENAME.EXT");
  3. open(FILE_HANDLE, "+>>FILENAME.EXT");
Mar 27 '07 #3

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

Similar topics

5
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got...
5
by: Hans-Joachim Widmaier | last post by:
Recently, there was mentioned how someone who had understood Python's error handling would write the "open and read file with error handling" idiom. If I remember correctly, it went like this: ...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
3
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
5
by: John Douglass | last post by:
I'm fairly new to doing involved file i/o and I came across something weird with a program I'm writing (modifying MIDI data, if it makes any difference). With some input files, when I modify data...
6
by: Cable | last post by:
Hello, I am hoping that someone can answer a question or two regarding file access. I have created an app that reads an image from a file then displays it (using OpenGL). It works well using...
2
by: Mullin Yu | last post by:
I create a component to write the error log as follow, but it seems sometimes locked by other processes, and pop up the I/O exception. How can we handling the concurrency issue at file level?...
1
by: Galen Somerville | last post by:
And yet another VB6 to VB2005 problem. All helpful suggestions appreciated. As you can see in the code below, my structures use fixed length strings and known array sizes. Consequently I can save...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.