How to Input Two Files and Search & Delete All Matches?
I am trying to create a program that will input two .css files.
CSS FILE 1 is simply a list of selectors with no properties. An example
below:
audio, canvas, video
audio:not([controls])
[hidden]
CSS FILE 2 is a normal css file with selectors and properties. An example
below:
article, aside, details, figcaption, figure, footer, header, hgroup, nav,
section, summary {
display: block;
}
audio, canvas, video {
display: inline-block;
*display: inline;
*zoom: 1;
}
audio:not([controls]) {
display: none;
height: 0;
}
[hidden] {
display: none;
}
Each line in CSS FILE 1 is a separate selector and there is only one
selector per line. The idea is, for each line, to search for the same
selector in CSS FILE 2 and delete the selector and everything following it
from the opening curly bracket { to the closing curly bracket }.
Since I am not very familiar with perl, I was looking to get started in
the right direction.
My question, how would I set the program up to input both CSS FILE 1 and
CSS FILE 2, and search CSS FILE 2 for the contents of each line found in
CSS FILE 1.
What I have so far is this:
#!/usr/bin/perl
use strict;
use warnings;
my $infile=<unused.css>;
my $infile2=<all.css>;
open(my $unused,'<', "$infile") or die $!;
open(my $all,'<',"$infile2") or die $!;
open(my $out, '>' ,'convertedback.css') or die $!;
my $lineU = <$unused>;
my $lineA = <$all>;
print $out "$lineU";
print $out "$lineA";
Thank you for your help in pointing me in the right direction.
No comments:
Post a Comment