hii, i have written a code to comment out certail lines in a file based on some condition. i want to apply comment and uncomment thing on this type of data: data -------
--------------------------------------- in this data if "one Link Start" is found without "--%>" and "second Link Start" is found with "--%>" character then trim "--%>" from "second Link Start" and append to "one Link Start" and vice versa. i have tried this code but not working. thanks in advance if anyone help me here.<%--JS one Link Start <script main="js src="js/libs/"></script> <%--JS one Link End <%--JS second Link Start--%> <script main="js/scripts Main" src="js/libs"></script> <%--JS second Link End--%>
#!/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 =~ /\s+.* one Link Start$/){ next unless($line=~/\s+.*second Link Start\s*--%>$/); $line =~ s/\s+--%>//; s/\s+.* one Link Start$/\s+.* one Link Start\s*--%>/gi; } elsif ($line =~ /\s+.* second Link Start$/){ next unless($line=~/\s+.*oneLink Start\s*--%>$/); $line =~ s/\s+--%>//; s/\s+.* second Link Start$/\s+.* second Link Start\s*--%>/gi; } } close $fh; print $line; open(my $output_fh, '>', 'hii.txt') or die "Unable to open file for writing: $!"; print $output_fh $line; close $output_fh;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |