seouri (owner)

Revisions

gist: 67465 Download_button fork
public
Public Clone URL: git://gist.github.com/67465.git
Embed All Files: show embed
read_write.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
sub read_file {
  my $file_name = shift;
  print STDERR "READ $file_name ... ";
  my @file;
  open(FH, "< $file_name") or die("Can't read $file_name: $!\n");
  while (<FH>) {
    chomp;
    my @t = split /\t/;
    @t = map { s/^\s+//g; s/\s+$//g; $_ } @t;
    push @file, \@t;
  }
  close FH;
  print STDERR scalar(@file), " lines\n";
  return \@file;
}
 
sub write_file {
  my ($file_name, @file) = @_;
  print STDERR "WRITE $file_name ... ";
  open(FH, "> $file_name") or die("Can't write $file_name: $!\n");
  print FH join("\n", map { join("\t", @$_) } @file), "\n";
  close FH;
  print STDERR scalar(@file), " lines\n";
}