title: How to pass and read a File handle to a Perl subroutine?
body: <p>I want a Perl module that reads from the special file handle, <code>&lt;STDIN&gt;</code>, and passes this to a subroutine. You will understand what I mean when you see my code.
  Here is how it was before:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict; use warnings;
  
  use lib '/usr/local/custom_pm'
  package Read_FH
  
  sub read_file {
  my ($filein) = @_;
  open FILEIN, $filein or die "could not open $filein for read\n";
  # reads each line of the file text one by one
  while(&lt;FILEIN&gt;){
  # do something
  }
  close FILEIN;
  </code></pre>
  
  <p>Right now the subroutine takes a file name (stored in <code>$filein</code>) as an argument, opens the file with a file handle, and reads each line of the file one by one using the fine handle.</p>
  
  <p>Instead, I want get the file name from <code>&lt;STDIN&gt;</code>, store it inside a variable, then pass this variable into a subroutine as an argument.
  From the main program:</p>
  
  <pre><code>$file = &lt;STDIN&gt;;
  $variable = read_file($file);
  </code></pre>
  
  <p>The subroutine for the module is below:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict; use warnings;
  
  use lib '/usr/local/custom_pm'
  package Read_FH
  
  # subroutine that parses the file
  sub read_file {
  my ($file)= @_;
  # !!! Should I open $file here with a file handle? !!!!
  
  # read each line of the file
  while($file){
  # do something
  }
  </code></pre>
  
  <p>Does anyone know how I can do this? I appreciate any suggestions.</p>