perl - Extract specific css classes in a file -


i'm trying use file all.css containing classes , want file green.css containing green classes.

i'm using perl css module, suggestions on how can use search lines contain .green , end { , extract css block ?

i'm new perl, far tried print selector lines matching "green" can't work:

my $css = css->new( { 'parser' => 'css::parse::lite'} );  print $stylesheetpath; $css->read_file($stylesheetpath);   open $filehandle, ">>", "green.css" or die "can't open 'green.css'\n";   #search lines contain .green , end { , extract css block   #and write green.css  serialize($css);   sub serialize{        ($obj) = @_;      $style (@{$obj->{styles}}){          print join "\n ", map {$_->{name}} @{$style->{selectors}};          if ( grep( /green/, @{$style->{selectors}} )) {            print "green matches ";             print $_->{name};          }         } } 

it helps read documentation of software working with. call get_style_by_selector method .green argument find styles.

use css qw(); $css = css->new; $css->read_string('.red { clear: both; } .green { clear: both; }'); $css->get_style_by_selector('.green')->to_string; 

Comments