package libfile;

use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION     = 1.00;
@ISA         = qw(Exporter);
@EXPORT      = ();
@EXPORT_OK   = qw(file_read file_write lines_print);

#--------------------------------------------------------
# read a text file and put it in a list.
#--------------------------------------------------------
sub file_read()
{
  my ($name)=(@_);
  my @l;

  open(FILE,$name)||die "couldn't open file $!\n";

  @l=<FILE>;
  close FILE;
  @_=@l;
}

#--------------------------------------------------------
# write a list into a text file
#--------------------------------------------------------
sub file_write
{
  my ($name,@l)=(@_);
  open(FILE,">$name")||die "couldn't write file $!\n";

  print FILE @l;
  close FILE;
}

#--------------------------------------------------------
# display a list with a number before each element
#--------------------------------------------------------
sub lines_print
{
  my (@n)=(@_);
  my $j=1;
  my $i;

  foreach $i (@n)
  {
    printf("%4d %s",$j,$i);
    $j++;
  }

}

1;

#@txt=file_read("libfile.pl");
#&lines_print(@txt);

#========================================================
__END__

=pod

=head1 file library

file subroutine manipulation.

=begin html
You can get the library  <a href="libfile.pm">libfile.pm</a>.

=end html

=head2 file_read

reads a text file and put it in a list.

  @t = &file_read("libfile.pl");
  &lines_print(@t);


=head2 file_write

writes a list into a text file

  &file_wite(rd.pl",@t);

=head2 lines_print

displays a list with a number before each element

  &lines_print(@t);

=head1 examples

=head2 read and display a file

require  libfile;

  #read the file
  @t = libfile::file_read("libfile.pl");
  # displat it with a line
  &libfile::lines_print(@t);

=cut
