I'm new to perl, some experience in python. I've been tasked to create a script to remove comments in files. So basically id like to remove <!-- comment here --> from every line that has it in an assortment of files in a directory tree. Some comments may span multiple lines.
I've done some research and this one here seems to want to remove anything. My test file looks like:
some code <!-- this is a comment-->
more code
And after i run the script, the file is empty.
script:
#!/usr/bin/perl
use File::Find;
use strict;
my $directory = "/home/rmcleod/perltest";
find (\&process, $directory);
sub process
{
my @outlines
my $line;
if ($File::Find::name=~/\.xsd$/) {
open (FILE, $File::Find::name) or
die "Cannot open file $!";
print "\n". $File::Find::name. "\n";
while ($line = <FILE>){
foreach ($line =~ /<!--.*?(^>]*)-->/is) {
push(@outlines, $line);
}
}
close FILE;
open(OUTFILE, ">$File::Find::name") or
die "Cannot open file:$!";
print (OUTFILE my @outlines);
close (OUTFILE);
undef (@outlines);
}
}
I've played around with some stuff. The foreach was an if statement, and before that was just the $line =~ regex. Which the guide I used had. But my limited knowledge of perl has kinda stopped me from any more playin around.
Thanks