perl removing unwanted characters

I’m new to perl. I’m planning to learn. I need to understand the following script. Can someone tell me what they are doing inside the script?

$ARGV[0] or die "Usage:tpreproc.pl <input file>n";
my $fullFilename = $ARGV[0];

my ($fnamePart) = ($fullFilename =~ /([^/]+)$/);

my $runtime = `date "+%Y-%m-%d %H:%M:%S"`;
chomp $runtime;

if ($fnamePart =~ /^(cj|lc|ond)_/i) {
  $runtime = ""$runtime"";
}

open my $inFH, '<', $fullFilename;
my $header = <$inFH>;
for my $aLine (<$inFH>) {
  next unless $aLine =~ /S/;
  chomp $aLine;

  $aLine =~ s/r//g;

  if ($fnamePart =~ /^(avl|ond)_/i) {
    $aLine =~ s/,s*$(d+),(d)/,$1$2/g;
    $aLine =~ s/,s*"$(d+),(d)/,"$1$2/g;
  }

  $aLine =~ s/$(d)/$1/g;

  if ($fnamePart =~ /^ond_/i) {
    $aLine =~ s/,$//;
    $aLine =~ s/(d) [ap]m"/$1"/g;
    $aLine =~ s/$-0/0/g;
  }

  if ($fnamePart =~ /^sas_/i) {
    $aLine =~ s/xAE/xC2xAE/;
  }

  if ($fnamePart =~ /^(avl|ir|lc)_/i) {
    $aLine =~ s/(([d.]+))/-$1/g;
  }

  if ($fnamePart =~ /^ir_/i) {
    $aLine =~ s/(([d.]+))/-$1/g;
  }

  print "$aLine,$runtimen";
}
close $inFH;

exit;


Source: regex

Leave a Reply