How to read multi lines from a file in perl?
Answer / Vibha Mishra
To read multiple lines from a file in Perl, you can use the `<FILEHANDLE>n` syntax. Here's an example:
```perl
open(my $fh, '<', 'filename') or die "Could not open file: $!";
while (my $line = <$fh>) {
print "$line";
}
close($fh);
```
This code opens the file 'filename' for reading, reads one line at a time into `$line`, and prints each line.
| Is This Answer Correct ? | 0 Yes | 0 No |
What are scalar data and scalar variables?
What are the different instances used in cgi overhead?
What are the various flags/arguments that can be used while executing a perl program?
What are some common methods to all handles in perl?
What does init 5 and init 0 do?
How many loop control keywords are there in perl?
How to open a directory in perl?
What are different data types that perl supports. Elaborate on them.
What is 'commit' command in perl?
There are some duplicate entries in an array and you want to remove them. How would you do that?
Write a simple regular expression to match an IP address, e-mail address, city-state-zipcode combination.
What are the logical operators used for small scale operations? Explain them briefly.