How to read multi lines from a file in perl?



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

Post New Answer

More CGI Perl Interview Questions

What are scalar data and scalar variables?

1 Answers  


What are the different instances used in cgi overhead?

1 Answers  


What are the various flags/arguments that can be used while executing a perl program?

1 Answers  


What are some common methods to all handles in perl?

1 Answers  


What does init 5 and init 0 do?

1 Answers  


How many loop control keywords are there in perl?

1 Answers  


How to open a directory in perl?

1 Answers  


What are different data types that perl supports. Elaborate on them.

1 Answers  


What is 'commit' command in perl?

1 Answers  


There are some duplicate entries in an array and you want to remove them. How would you do that?

1 Answers  


Write a simple regular expression to match an IP address, e-mail address, city-state-zipcode combination.

15 Answers  


What are the logical operators used for small scale operations? Explain them briefly.

1 Answers  


Categories