i made some modification in reg exp in the code written by stevieb and it's working fine for this type of data
data
---
<script type="java/js">
foobie bletch
</script>
<%-- <script>
zelgo mer
</script> -->
but problem is if i write endi script tag </script> not in the first column,it's not commenting or uncommenting that.
#!/usr/bin/perl
use warnings;
use strict;
open my $fh, '<', 'hii.txt' or die "Can't open the damn file for readi
+ng!: $!";
my @file_content;
while ( my $line = <$fh> ){
chomp $line;
if ( $line =~ /^<script(.*)>/ ){
$line = "<%-- $line";
push @file_content, "$line\n";
next;
}
elsif ( $line =~ /^<\/script>$/ ){
$line .= " -->";
push @file_content, "$line\n";
next;
}
elsif ( $line =~ /^<%--\s+<script(.*)>/ ){
$line =~ s/^<%--\s+//;
push @file_content, "$line\n";
next;
}
elsif ( $line =~ /^<\/script>\s+-->/ ){
$line =~ s/\s+-->//;
push @file_content, "$line\n";
next;
}
push @file_content, "$line\n";
}
close $fh;
open $fh, '>', 'hii.txt' or die "Can't open the damned file for writin
+g: $!";
print $fh @file_content;
close $fh;
|