ulaksh has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; my ($filename, $lines_num, $line, $c); $lines_num = 0; $filename = "input.txt"; open my $in, "<", $filename; while ($line = <$in>) { $c = substr($line, 0, 1); if (lc($c) eq "x") { $lines_num++; } } close($in); print "In " , $filename, " there are ", $lines_num, " lines that start with \"X\".\n";
And my output show "readline() on closed filehandle $in at filehandleoperator.pl line 12."my input file contains as below X XX XXX XXXX XXXXX XXXXXX XXXXXXX XXXXXXXX XXXXXXXXX XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: readline() on closed file-handle is coming when reading the file
by philiprbrenan (Monk) on Aug 30, 2012 at 22:38 UTC | |
by johngg (Canon) on Aug 31, 2012 at 08:50 UTC | |
|
Re: readline() on closed file-handle is coming when reading the file
by 2teez (Vicar) on Aug 30, 2012 at 23:41 UTC |