in reply to appending a unique marker to each url in a file
I think using a regex on the entire file may get a little complicated.
Update: fixed the way data was put into $content courtesy of Hofmator.
I would use HTML::TokeParser to pull the links out of your file and then modify them from there, like so
#!/usr/bin/perl -w use HTML::TokeParser; use strict; my $i=0; ## set marker definintions my @markers = qw/ anfnf11 iopi1p83288 9032-jjjf /; my $htmlfile = "index.html"; my $content; ## get contents of your html file open (FILE," $htmlfile") || die "Cannot open HTML file for parsing!: $ +!\n"; while(<FILE>) { $content .= $_; } close(FILE); my $parse = HTML::TokeParser->new(\$content); while (my $token = $parse->get_tag("a")) { my $url = $token->[1]{href} || "-"; ## put link into $url my $text = $parse->get_trimmed_text("/a"); ## put link de +sc into $text if ($markers[$i]) { print "<a href=$url/$markers[$i]>$text</a>\n"; } else { ## no more markers... } $i++; } exit;
Update: fixed the way data was put into $content courtesy of Hofmator.
-p
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: appending a unique marker to each url in a file
by Hofmator (Curate) on Aug 08, 2001 at 14:14 UTC | |
by tachyon (Chancellor) on Aug 08, 2001 at 17:36 UTC | |
by chipmunk (Parson) on Aug 08, 2001 at 17:59 UTC | |
by tachyon (Chancellor) on Aug 08, 2001 at 18:32 UTC |
In Section
Seekers of Perl Wisdom