in reply to Regexp conundrum

Well, the syntax of lines 11 and 12 isn't quite right. If you're trying to save a regex to a variable for later use, then what you want is:
my $pattern1 = qr/(word)-(spacing):\s*[\d]+px/; # word spacing regexp my $pattern2 = qr/(letter)-(spacing):\s*[\d]+px/; # letter spacing r +egexp
This will compile each regex to that variable.

I don't really know why you have a sub inside a while loop, or why there's a for loop inside that sub. I would recommend just using one big for loop, like so:

foreach my $line (@htmlLines) { if(/$pattern1 && $pattern2/) { printHTML(); } else { notFound(); } }
You don't need the while loop (which wasn't doing what you wanted anyway - it would have looped forever), and you don't really need the extra sub anyway.

The code in the if clause is also not likely to do what you want. Personally, I would recommend avoiding compiled regexes (like those on lines 11 and 12). So take out lines 11 and 12 and replace the if clause with this:

if(/(word)-(spacing):\s*[\d]+px/ && qr/(letter)-(spacing):\s*[\d]+px/)
The printHTML function is getting called on every iteration through the loop, which is probably unnecessary. The notFound sub is superfluous, but won't cause you any problems.

To be brutally honest, this code doesn't make much sense. Could you explain exactly what you're trying to do? This way, we can help you get where you're trying to go.


milkbone - perl/tk instant messaging - it's the only way to fly

Replies are listed 'Best First'.
Re: Re: Regexp conundrum
by Tricky (Sexton) on Aug 22, 2003 at 09:26 UTC
    Hello monks, I'm scrambling around too much, and not thinking about what I'm doing; I'm a newbie to coding, and still finding my feet.
    1. My aim (for today) is to read-in the HTML file on a filehandle, che +ck for the presence of the word and letter spacing attributes and pri +nt out a 'success, patterns are in the document' message.
    2. Next is to remove the attributes with 'substitute', write the coore +ctions to the HTML source file, and open the browser to see if the it +s worked.
    3. I'm going to remove the attributes from the styles (in-line styles + at the moment), check the source file for the absence of them, and r +e-include them within the tags.
    I want to see how I can change the HTML using regexps, from a dyslexic/poor-vision user's point-of-view. Word and letter spacing, Linearising hyperlinks and removing unnecessary emphasis of text (confusing for dyslexics - I should know, I'm one of them!) are some of the requirements I've identified. I've managed to extract image tags and re-write the changes, so I'm heading in the right direction. Question: I've not encountered the 'qr' modifiers before; what are they, and what do they do?
    Thanks for your patience, brethren...