ここで何かが大きく間違っていることは知っていますが、私は Perl に不慣れで、次のことをしようとしています:
unused.css 内の行を含む all.css 内のすべての行を検索し、いくつかのロジックを実行します。私のコードが構造化されている方法は、次のようなものと一致しないようです:
if ($lineA =~ /$lineU/) #all.css の行に unused.css の行が含まれている場合
変数が別々に定義されているためです。
all.css の行と unused.css の行を一致させるには、プログラムをどのように構成すればよいでしょうか?
私のプログラムは以下の通りです:
#!/usr/bin/perl
use strict;
use warnings;
open(my $unused_handle,'<', "unused.css") or die $!;
open(my $all_handle,'<',"all.css") or die $!;
open(my $out, '>' ,'lean.css') or die $!;
my $lineU = q{};
my $lineA = q{};
print $out "$lineU";
while($lineU =<$unused_handle>) {
print $out "$lineU";
#print $out "$lineA"; Line One not printed from All
while($lineA =<$all_handle>) {
if ($lineA =~ m/$lineU/sxm) {
print "Huza!\n";
}
else {
print "No Match\n";
}
}
}
close ($unused_handle);
close ($all_handle);
close ($out);
print "Done!\n";
exit;
私の入力ファイルの例を以下に示します。
unused.css の行の例:
audio, canvas, video
audio:not([controls])
[hidden]
h6
all.css の行の例:
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;
}