arunkumar.rk141 has asked for the wisdom of the Perl Monks concerning the following question:
i'm trying to update a file reading logic in modules. But it is not giving the expected results.
with the below code, file reading is not happening inside the main file. Could you pls advise on this? Also you can suggest best practise of reading the files(passed as either arg or as an input through STDIN) inside a module without making any changes in main file
fileread.pl:
use file_read; my $a=0; while(<STDIN>){ $a+=1; } print "$a";
file_read.pm:
package file_read; while(<STDIN>){ print; } 1;
perl fileread.pl </tmp/file
Output : contents of the /tmp/file and $a value is printed as 0 but not 1
2020-06-16 Athanasius added <code> and <p> tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Usage of STDIN for file reading inside a module
by haukex (Archbishop) on Jun 15, 2020 at 09:06 UTC | |
|
Re: Usage of STDIN for file reading inside a module
by jcb (Parson) on Jun 16, 2020 at 01:51 UTC |