Home / Interview / Perl :: General Questions

Interview :: Perl

71)

How will you open a file in read-only mode in Perl?

To open a file in read-only mode, '

72)

How will you open a file in a write-only mode in Perl?

To open a file in write-only mode, '>' sign is used. The file you open will be emptied or truncated if it already exists if not, a new file will be created.

73)

How to prevent file truncation in Perl?

Opening a file in write-only mode truncates data of the file. To prevent it, use sign '+>'. It will prevent your data, and you can append new data in the last of the file.

74) What is the use of '>>' in Perl?

The '>>' sign opens a file with appending purpose. It places the pointer at the end of the file where you can add new data.

click here.

75)

How to read a single line from a file in Perl?

Taking $row = as a variable will print a single line from the file

76)

How to read multi lines from a file in Perl?

Taking $row = as a variable in a while loop will print all lines from the file.

77)

How to close a file in Perl?

Closing a file in Perl is not mandatory. However, using close() function will disassociate the file handle from the corresponding file.

78)

How to copy a file in Perl?

To copy the content of one file into another file, read all lines of the first file in a while loop and copy it in another file.

79) Explain '->' in Perl?

It is a symbolic link which links one file name to a new file name.

For example, in file1 -> file2, if we read file1, we will end up reading file2.

80) Explain a tell function in Perl?

The tell function finds your position within a file. It is the first thing you need to do during file handling.