English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

print("filename :: ");
chomp ($name = );

$newfile = "$name.txt";
open(FILE, "$name.txt") or die "Couldnt open file.";

i want $name.txt to be created so i can write information to it from this perl program. Can anyone shed any information??
Thanks.

2007-06-17 04:04:41 · 3 answers · asked by Jaaaaaaay 1 in Computers & Internet Programming & Design

3 answers

In Perl, open by default opens for READING.

You can explicitly say whether you are reading or writing, by placing a greater-than or less-than character in front of the filename:

open FILE, "<${name}.txt" (open for read)
open FILE, ">${name}.txt" (open for write)
open FILE, ">>${name}.txt" (open for append)

2007-06-17 04:07:59 · answer #1 · answered by McFate 7 · 0 0

Create File Perl

2016-10-31 05:47:31 · answer #2 · answered by ? 4 · 0 0

To create (over-writing if it exists) the file, use:

open (FILE, ">", $filename) || die "Could not open file $filename";

To append to the file, use:

open (FILE, ">>", $filename) || die "Could not open file $filename";

You should get in the habit of using the three argument form of open. If you use the two argument form and allow users to provide their own filenames, you are potentially opening a security hole.

For example:

open (FILE, $filename);

Imagine if the user provides a filename with a '>' as the first character. Depending on the unix permissions, they can potentially truncate arbitary files on your system.

2007-06-19 03:50:39 · answer #3 · answered by Justin H 1 · 0 0

Jay here is your link

http://www.google.co.uk/search?hl=en&q=IN+PERL+how+to+create+a+new+file+to+output+data+to&meta=

2007-06-17 04:08:52 · answer #4 · answered by Joe_Young 6 · 0 0

fedest.com, questions and answers