while - executes as long as there is something in $line, as long as there are lines in the file
Loop over file (name hardcoded) and print every line (UNIX cat)
Example 6-5. examples/files/cat.pl
#!/usr/bin/perl
use strict;
use warnings;
my $filename = "input.txt";
open(my $fh, "<", $filename) or die "Could not open '$filename'\n";
while (my $line = <$fh>) {
print $line;
}
Instead of printing the line you could do anything with it.
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Read one line from a file | Up | Write to a file |