2.Program code

5 views
Skip to first unread message

darshan kr

unread,
May 17, 2012, 12:47:59 PM5/17/12
to sjbit...@googlegroups.com
2. Program Code

 #!/usr/local/bin/perl
$infile = "foo.txt" ;
$outfile = "bar.txt" ;
$scrapfile = "baz.txt" ;
open(INF,"<$infile") || die "Can't open $infile for reading" ;
open(OUTF,">$outfile") || die "Can't open $outfile for writing" ;
open(SCRAPS,">$scrapfile") || die "Can't open $scrapfile for writing" ;
chop($date = `date`) ; # run system command, remove the newline at the end
foreach $line (<INF>) {
if ($line =~ /IgNore/) {
print SCRAPS $line ;
next;
}
$line =~ s/\*DATE\*/$date/g ;
if ($line =~ /\#/) {
@parts = split ("#", $line);
print OUTF "$parts[0]\n" ;
print SCRAPS "#" . @parts[1..$#parts] ; # range of elements
} else {
print OUTF $line ;
}
}
close INF ; close OUTF ; close SCRAPS ;
Reply all
Reply to author
Forward
0 new messages