# expl7.pl  example  read and write files
use strict;
use warnings;

print "perl  expl7.pl  running\n";
print "perl expl7.pl  aa bbb cccc < expl7.dat > expl7.out";

my $num_args = $#ARGV + 1;
my $filename = 'cmd_pl.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh "args from cmp.pl \n";

print "num_args=$num_args \n";
print $fh "num_args=$num_args \n";

for(my $i=0; $i<$num_args; $i++)
{ 
  print "$ARGV[$i] \n";
  print $fh "$ARGV[$i] \n";
}

print "STDIN is: \n";
print $fh "STDIN from expl7.dat \n";
foreach my $line ( <STDIN> )
{
  chomp( $line );
  print "$line \n";
  print $fh "$line \n";
}
print "\n";

print $fh "end of STDIN\n";
close $fh;

print "expl7.pl finished\n";
