Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Have you thought about using split

# for example: use strict; use warnings; my $CSS = ""; my $filename = shift (@ARGV) || die ("No file in \@ARGV!"); open ("FILE", "< $filename") or die ("Cannot open $filename $!"); $CSS .= $_ while (<FILE>); close ("FILE") or die ("Cannot close $filename $!"); # CSS is of the form: # H1 { /* CSS */ } # where H1 is the HTML element # what's in {} is what to do # and /* */ is comments # so get rid of comments $CSS =~ s[/\*.*?\*/][]sg; # now get what's in between the {}s my @parts = split /\}/, $CSS; while (@parts) { my $part = shift (@parts); # now we should have CSS of the form # H1 { directives my ($HTML_element, $CSS) = split /\{/, $part, 2; # note that the HTML element we're working on is in # $HTML_element # now get the CSS directives my @directives = split ';', $CSS; # now each CSS directive i.e. # font-family: Verdana, Arial, Geneva # has been brokon off foreach my $directive (@directives) { my @parts = split ':', $directive; # $parts[0] is font-family my @fonts = split ',', $parts[0]; # @fonts is all the different font families } }

You'll note I did what I did because CSS states that there's a : after a property, i.e. font-family and that there are commas between different options. In any event, why not go to CPAN and pick up a ready made CSS parser? What I did was just a quick hack, and although it should give you some direction on what you can do, it almost certainly won't work nearly as well as a CPAN module -- of which there are many.


Want to support the EFF and FSF by buying cool stuff? Click here.

In reply to Re: regex question by Vautrin
in thread regex question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-07-02 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (103 votes). Check out past polls.

    Notices?