How do you open a file for writing?
Answers were Sorted based on User's Feedback
Answer / raj
Files are opened using the open and sysopen function.
Either function may be passed up to 4 arguments, the first
is always the file handle thenfile name also known as a URL
or filepath, flags, and finally any permissions to be
granted to this file.
$FH = "filehandle";
$FilePath = "myhtml.html";
open(FH, $FilePath, permissions);
or
sysopen(FH, $FileName, permission);
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / raghav
To open a file:
open (FILE, "<raghav.txt") || die ("File Cannot be opened");
Where FILE is the file handle for this file.
Here the file is opened in read mode.
Put > for write mode
put >> for append mode.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ankur
open FP,">","myfile.txt";
print FP "Hello World!!";
close FP;
# > for write
# < for read
# >> for read and write
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / ankur
open FP,">","myfile.txt"
print FP "Hello World!!";
close FP;
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / shri
Open(FH,">>File.log");
print FH "Hello";
Close FH;
| Is This Answer Correct ? | 3 Yes | 8 No |
How to create a directory in perl?
What is caller function in perl?
What are the various perl data types based on the context?
There are some duplicate entries in an array and you want to remove them. How would you do that?
What are perl array functions?
Explain the use of 'my' keyword in perl?
What is subroutine in perl?
how to get back up from private character editor which is saved in the format of .udf
What elements of the Perl language could you use to structure your code to allow for maximum re-use and maximum readability?
what is perl language?
what is the function that is used to identify how many characters are there in a string?
Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?