Heidegger has asked for the wisdom of the Perl Monks concerning the following question:

Hello, monks,

We have a lot of mess in our CSS files. I want to write a perl script that lists all styles defined in a given *.css file.

I have tried the CSS::Tiny, CSS::SAC and CSS modules. In none of the examples I could understand how to print all the styles found in a *.css file.

Here's an example code that doesn't fetch styles for me:

use CSS; my $stylesheet = CSS->new(-source => "myfile.css"); my @styles = $stylesheet->styles; # Here the $styles[0] is undefined.

So has anyone needed this? How to do it? Thank you very much for your help.

Replies are listed 'Best First'.
Re: Listing CSS style entities
by Heidegger (Hermit) on Apr 01, 2003 at 10:30 UTC

    I have solved this problem myself. Here's the code that prints all css styles from a given *.css file.

    #!C:\Perl\bin\perl -w use CSS::Tiny; $CSS = CSS::Tiny->read($ARGV[0]); foreach (sort keys %$CSS) { print $_."\n"; }
Re: Listing CSS style entities
by benn (Vicar) on Apr 01, 2003 at 09:25 UTC
    I haven't used this module myself, but as your example code is straight out of the CSS POD, it may be that your CSS file is invalid - have you tried it with the W3C CSS Validator ?

    Try checking the value of $stylesheet after the CSS->new call.

    Cheers,
    Ben