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

New to Perl and File IO

Hi everybody,
I am new to Perl (in Vietnam, Perl is a new program to learn)
I've got some first parts of Perl
I am having some problems with I/O handle
How can I create a new text file, save it, open and append it
I don't understand the words in the book
Please tell me know how to take it
Thanks
Sep 5 '07 #1
1 1704
numberwhun
3,509 Expert Mod 2GB
Welcome to TSDN and Welcome to Perl!

First, I would suggest you read the online book Beginning Perl. This will definitely help you get started.

Second, there are many references on the web that you will want to visit quite frequently. CPAN is where you will find all of the Perl modules for use in your coding. Perldoc is where you will find loads of documentation on all things Perl.

Speaking of perldoc, a couple of pages you should examine regarding opening and adding to files are the open() function, which is what is used in perl to open files for reading, writing, reading/writing, appending, etc. And, the perlfunc page, which goes over the standard functions that are included in the default distribution of Perl.

When you open a file, for writing to for instance, you would use the following syntax:

Expand|Select|Wrap|Line Numbers
  1. open(FILEHANDLE, ">./file.txt");
  2.  
This will first check and see if file.txt exists in the current directory. If it does not, it creates it, then, it opens it for writing to. The ">" tells perl it is only to write to the file. FILEHANDLE is the file handle you would use when referencing the open file. Here is how you would print a line of text to the open file:

Expand|Select|Wrap|Line Numbers
  1. print FILEHANDLE ("Print some text to the file.\n");
  2.  
That will output to the opened file referenced by FILEHANDLE. This is just an example to get you started. Read the open() function page I gave you a link to and it will explain more for you. Plus, the online book link I provided will also go over that, plus a whole lot more.

If you have any further questions, please do not hesitate to ask them here. If you are asking about code you are working on, please be sure to provide that code here so we can see it and help you. When supplying code in your postings though, please put code tags around the code as well.

Regards,

Jeff
Sep 5 '07 #2

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

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.