Hello
I'm feeling pretty ashamed to ask this, but i've been trying for pretty long now to no avail, and also searching perlmonks and google didn't point me to any hints. So I'm asking it here.
I have the following code, which should do nothing less than to transform pseudo-html line into real html. The problem where everything fails is in the final translation. The regex isn't "working" as expected. I guess it has something to do with $complete containing characters, that represent special chars to a regex (like / . [] etc).
any help on this would be greatly appreciated
#!/usr/bin/perl -w
use strict;
my $source = <<EOF;
[link title:Google]http://www.google.com[/link]
[link title:Altavista]http://www.altavista.com[/link]
[link title:perlmonks]http://www.perlmonks.com[/link]
[link title:and now something completely different]http://www.perlmonk
+s.com/index.pl?node_id=104944[/link]
EOF
my ($complete,$title,$url);
while ($source =~ /(\[link title:(.*?)\](.*?)\[\/link])/gi)
{
$complete = $1;
$title = $2;
$url = $3;
print "complete: $1\ntitle: $title\nurl: $url\n";
$source =~ s/$complete/<a href='$url'>$title<\/a>/g || print "
+regex failed\n";
}
print $source."\n";
Emanuel
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.