So, I ran into this guy that was very impressed with himself that he wrote a php script that reads a css file, parses it into a data structure, then prints it out, and that he wrote it in only 20 minutes. I was sitting at o'hare airport waiting for a plane so I decided to impress myself back by writing one in perl shorter, faster and parsing into a fuller data structure. Here it is:
perl -lne'chomp;@a=split/:/;push@{$h{$1}},[@a]if(/(.+){/../}/)&& length($a[1]);END{for(keys%h){$h{$_}=~s/$_.*{|\t//g;print"$_ {"; for(@{$h{$_}}){print" $_->[0] : $_->[1]";}print"}\n"}}' test.css
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: CSS parsing
by ambrus (Abbot) on Jun 15, 2005 at 15:11 UTC | |
by ww (Archbishop) on Jun 15, 2005 at 17:12 UTC | |
by ambrus (Abbot) on Jun 15, 2005 at 19:15 UTC |
Back to
Obfuscated Code