title: Reading and printing file contents using Perl
body: <p>Can any body help me in reading all the files of particular format from the directory line by line and it should print on screen.</p>
  
  <p>And my request is to include command lines in the program itself.</p>
  
  <p>Then when ever simple I ran the program , it should display all the content of files.
  Below is the program I wrote can any body help me please....</p>
  
  <pre><code>#!/usr/local/bin/perl
  $filepath="/home/hclabv";
  opendir(DIR,"$filepath");
  @files=grep{/\.out$/} readdir(DIR);
  closedir(DIR);
  $c = 0;
  for ($c=0 ;
  while ($c &lt;= @files)
  {
  $cmd = "Perlsc11 $files[$c]";
  system($cmd);
  if($#ARGV != 0) {
     print STDERR "You must specify exactly one argument.\n";
  exit 4;
  }
  else
  {
  print ("$files[$c]\n");  
  # Open the file.
  open(INFILE, $ARGV[0]) or die "Cannot open $ARGV[0]: $!.\n";
  while(my $l = &lt;INFILE&gt;) {
  print $l;
  }
  close INFILE;
  }
  $c++;
  }
  </code></pre>