472,950 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

editing a file using perl script

Hi,
I don't have a code to show you, what I need are references or
algorithms so that I'm in a right track.

By the way, thanks for introducing me the array or arrays. Now I can
continue my script.

Now I want to delete a line from a file. Line being the strings I
got/saved to/from array of arrays.

This website tells me I have to open my file and create a new file and
put my changes to the new file.
http://www.rocketaware.com/perl/perl...ne_in_a_fi.htm

So here's what I have in mind, or questions on what should I do?
-create a new blank file
-open my existing file where it is full of strings with spaces, \n...etc.
-where do I make my changes?
-how will all the strings from existing file gets copied to new file?
-will I need to save all the existing file strings to array of array or
just array? what will be my separator?
-then when do I do the copying to new file? Before of after deletion of
strings from my array of arrays?
-when or where can I do the deletion?

Sorry about all the questions? I just can't start coding this if I don't
know what to do. Please feel free to tell me websites or which perldoc
I would be needing to research on.

Thanks.

Jan 2 '06 #1
2 15928
kelly wrote:
By the way, thanks for introducing me the array or arrays. Now I can
continue my script.
No idea what you are talking about, please quote appropriate context when
refering to an earlier article.
Now I want to delete a line from a file. Line being the strings I
got/saved to/from array of arrays.


Your Question is Asked Frequently, see
perldoc -q "delete a line"

jue
Jan 3 '06 #2
In article <43**************@some.com>, kelly <ke***@some.com> wrote:
Hi,
I don't have a code to show you, what I need are references or
algorithms so that I'm in a right track.

By the way, thanks for introducing me the array or arrays. Now I can
continue my script.
Whom are you thanking? Please include some context.
Now I want to delete a line from a file. Line being the strings I
got/saved to/from array of arrays.

This website tells me I have to open my file and create a new file and
put my changes to the new file.
http://www.rocketaware.com/perl/perl...ne_in_a_fi.htm
The first method on this web page is a typical way of modifying a file.
You should try using it on your file. You should write out your
modified file using a new name and don't rename it or overwrite the
existing file. Inspect the contents of the modified file manually until
you are satisfied that it is correct before coding your program to
overwrite the contents of your existing file.

So here's what I have in mind, or questions on what should I do?
-create a new blank file
-open my existing file where it is full of strings with spaces, \n...etc.
-where do I make my changes?
Make your changes in the strings that contain the lines from the old
file after you have read them in but before you write them out.
-how will all the strings from existing file gets copied to new file?
You will write out the lines using the print statement.
-will I need to save all the existing file strings to array of array or
just array? what will be my separator?
If you read each line and then write it out, you needn't save it. You
would only save it if you needed to change more than one line at a time
or for some other reason.
-then when do I do the copying to new file? Before of after deletion of
strings from my array of arrays?
You don't need an array of arrays to modify a file. You only need one
scalar variable to hold each line, as demonstrated by the solution
given on your referenced web page.
-when or where can I do the deletion?
You can delete a line by not writing it to the modified file.

Sorry about all the questions? I just can't start coding this if I don't
know what to do. Please feel free to tell me websites or which perldoc
I would be needing to research on.


You are confusing two different methods for modifying a file. One is to
read the lines of the file into an array (not an array-of-arrays),
modify the array, then write out the array to a modified file. The
other method is to read one line at a time from the old file, modify
the line if necessary, and write the line out to the file if it should
be kept.

Pick one method and stick with it. The first method will have less
memory usage. The second method allows you to modify more than one line
at a time. Use whichever method suits your purpose.

The first method may be implemented using the Tie::File module, as
Jürgen has recommended. However, I recommend you implement your own
method until you understand programming in Perl better.

See the following for more info:

perldoc -f open
perldoc perlop (and search for "I/O Operators")

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jan 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: TaeKyon | last post by:
I'm a python newbie; here are a few questions relative to a problem I'm trying to solve; I'm wandering if python is the best instrument or if awk or a mix of bash and sed would be better: 1) how...
1
by: von | last post by:
I am trying to write a single piece of data (that is generated from a Javascript) to a text file on my server via a Perl script. The Javascript is setup so that I can display the required data on...
12
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
2
by: oscar78 | last post by:
Hi, I am trying to write a perl script that will read a three-column data file and write certain lines of it in to a new data file according the ranges of values that each of these lines contain. ...
1
by: raghav82 | last post by:
New to perl. c++ file which needs to invoke perl file and provide input for it.how to invoke it.i also want to know setting of environment variable in windows environment using the perl script. i set...
1
by: georgewa | last post by:
Greetings all, great forum, this is my first post. Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.