Assume the file contains 10 words and we need to find the longest word and print on the console with help of perl script. Following are different ways to open a file and read the content using perl
- less than < sign indicates that file has to be opend in read-only mode.
- greater than > sign indicates that file has to be opend in the writing mode.
- To open a file for updating without truncating it
- To truncate the file first
open DATA, “+>vlsispace.txt”
- In this mode, writing point will be set to the end of the file and append new data to file
- To read the data in a file during append process
open r,”<data.txt” or “cannot open the file”;
print “the longest word:$word\n”;
print “the length of the longest word:$max\n”;