Xxaxx has asked for the wisdom of the Perl Monks concerning the following question:
The code snippet below works but I was wondering if there is a better way.
I could do the leading slash stuff with:..... my ($urltop) = 'http://www.somewhere.com/'; my ($urltodir) = 'http://www.somewhere.com/folder/'; my(@matches) = ($content =~ /href="([^"]*)"/gi); foreach my $match (@matches) { if ($match =~ /^http/i) { ## absolute leave alone } elsif ($match =~ /^\//) { $content =~ s/href="$match"/href="$urltop$match"/gi; } else { $content =~ s/href="$match"/href="$urltodir\/$match"/gi; } }
But I can't figure out how to do the other matches without the foreach.$content =~ s/href="^\/([^"]*)"/href="$urltop/$1"/gi;
Thanks for any clues
Claude
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex question: Is there a better way?
by Beatnik (Parson) on Apr 22, 2001 at 17:53 UTC | |
by Xxaxx (Monk) on Apr 22, 2001 at 23:25 UTC | |
by cLive ;-) (Prior) on Apr 23, 2001 at 00:31 UTC | |
|
Re: Regex question: here's the lazy way
by cLive ;-) (Prior) on Apr 23, 2001 at 00:16 UTC |