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 |
What is the difference between chop & chomp functions in perl?
10 Answers Cap Gemini, DELL, Electronic Data, TCS,
What are the two ways to get private values inside a subroutine?
Which functions in Perl allows you to include a module file or a module and what is the difference between them?
Explain what is perl language?
What is hash?
write a script to display mirror image of a entered value and also check whether Palindrome
how to create a flat file database as shown below s.no name age city phone 0 hema 22 Calcutta 4312542 1 hema 21 Bangalore 2344345 2 ganesh 25 delhi 2445454 3 kartik 45 pune 4312121 4 santosh 25 Hyderabad 2254231 5 kumar 25 mysore 2344567 6 gita 34 mangalore 6532123 7 gita 32 pune 2213456 Q1.print the details of the person who r from bangalore q2.Replace the city name managlore to pune q3.prints no of person having name gita and hema q4.print how many are of age 25.
You want to open and read data files with perl. How would you do that?
What is the difference between exec and system?
write a script to generate n prime no.s?
Comment on data types and variables in perl.
How to replace perl array elements?