Article View: comp.lang.perl.misc
Article #48Re: Writing to file?
From: Rodrigo Vanegas
Date: Sat, 09 Dec 1995 00:00
Date: Sat, 09 Dec 1995 00:00
34 lines
1471 bytes
1471 bytes
In article <4a54h9$a0g@shellx.best.com> Zenin <zenin@best.com> writes:
> I can't seem to figure out how to write to a file.
> I thought it was somthing like
> write(FOO, "filename");
>
> but I guess it's no so easy. :(
>
> So what is the syntax to do somthing like:
> #!/usr/bin/perl
> open(FOO, "original_filename");
> while(<FOO>) {
> do some stuff;
> }
> write(FOO, "new_filename");
> close FOO;
>
The FOO is a filehandle associated with the open file. So for
starters, I don't think you want to use FOO for both files. What is
it you want to write to "new_filename" anyway? It's clear from your
code above.
Here's how to read a line from one file and write it to another.
open(FILE1,"one");
$line = <FILE1>;
open(FILE2,"> another");
print FILE2 $line;
close(FILE1);
close(FILE2);
--
Rodrigo <Vanegas@bbn.com>
Technical Details
Message-ID:
<VANEGAS.95Dec9010144@jade.bbn.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4a54h9$a0g@shellx.best.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f9f6d,3944997a5420a56f X-Google-Attributes: gidf9f6d,public X-Google-Thread: fa0ae,3944997a5420a56f X-Google-Attributes: gidfa0ae,public X-Google-Thread: 112e82,3944997a5420a56f X-Google-Attributes: gid112e82,public From: vanegas@jade.bbn.com (Rodrigo Vanegas) Subject: Re: Writing to file? Date: 1995/12/09 Message-ID: <VANEGAS.95Dec9010144@jade.bbn.com> X-Deja-AN: 121364997 references: <4a54h9$a0g@shellx.best.com> organization: BBN reply-to: vanegas@bbn.com newsgroups: comp.lang.perl.misc,best.unix,best.general