html tags and perl

K

Kio

hi,

I've got a perl script which is parsing a HTML file and printing a src
text from a <img> tag on a screen.

I dont know how to write a sub which can take a html $file and change
all the src contents from the img tags to sth else. I dont want to use a
regexp.

for example:

<img src="xxx.jpg"> change to <img src="zzz.jpg">

Thx for you help
Damian
 
K

krakle

I dont want to use a
regexp.

Why not?
for example:

<img src="xxx.jpg"> change to <img src="zzz.jpg">

$file =~ s/xxx\.jpg/zzz\.jpg/g;

Now why would you want to use more code for a slower less efficient
way to replace just to avoid regex?
 
K

Kio

Abigail napisa³(a):
That's silly.

No it's not.
If you want to code with articificial restrictions (in this
case "don't use regular expressions"), you're better off asking your question
in a more appropriate forum.

I can use regexp for those:

<img src="whatever.jpg">

and than change it ...

but if i would have sth like:

<img alt="aa" src="whatever.jpg"> whats then ? regexp is not gonna work
on it :/

what about links situated in JS ? regexp is not gonan work again :/


Damian
 
K

Kio

(e-mail address removed) napisa?(a):

cause in some examples its not gonna work
$file =~ s/xxx\.jpg/zzz\.jpg/g;

OK but i have to change the path for all the IMG SRC , JUST those !!
sometimes you can have .jpg, .png or .gif etc.

you can have:
<img src="a.jpg">
<img src='a.jpg'>
<img src=a.jpg>
<img alt="a" src="a.jpg">
etc.
or even img src in JS like: src\="" whatever ...

you have to know that other tags have SRC as well, i have to change just
those from IMG

Damian
 
K

Kio

Michele Dondi napisa?(a):
Earlier today someone posted a question about HTML::TokeParser, and
people answered giving some explicit example. You may enjoy reading
that thread. Your case is actually easier than what was being asked
there...

I wrote sth like this:

use HTML::TokeParser;
my $p = HTML::TokeParser->new(\$html_file);
while (my $token = $p->get_tag('img'))
{
#how can i write sth to the src attr ?
#like: new attr="/e/.jpg"
}

Damian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top