CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
searching and replacing

 



zanardi
journeyman

Jan 31, 2001, 2:32 PM

Post #1 of 5 (424 views)
searching and replacing Can't Post

I've got a sub routine here that partially works, this basically sums it up.

Im taking a string, that is just text, like this post right here. Then I search the string for characters, and replace them, sounds simple because it is. But the problem is I dont know what 'characters' im searching for because they are in a file. An example of the file is this:

:)=$noncgiurl/images/smilies/smile.gif=1
:(=$noncgiurl/images/smilies/frown.gif=2
;)=$noncgiurl/images/smilies/wink.gif=3

the characters are ":), :(, ;)" and so on, there might be more there might be less, all depends on what the user wants. Ok so here is my sub to process this:

$text = Replace($text);


Code
sub Replace { 
my ($text) = @_;

open(DATA,"smilies.dat") or die $!;
my @smilies = <DATA>;
close DATA;

for (@smilies) {
my ($face,$url,$id) = split(/=/,$_);
$face =~ s/\)/\\)/isg;
$face =~ s/\(/\\(/isg;
$face =~ s/\:/\\:/isg;
$face =~ s/\;/\\;/isg;

$url =~ s/\$noncgiurl/$noncgiurl/isg;

$text =~ s/$face/<img src=\"$url\">/sg;
}

return $text;
}

for alot of characters this does work, but say I add some normal text in there to replace, the variable returned is just full of my 'images' and doesn't work at all.. I just need some help in finding a better way to do this.


My BBS


abockover
Deleted

Feb 10, 2001, 1:09 PM

Post #2 of 5 (403 views)
Re: searching and replacing [In reply to] Can't Post

This might help:

$string = "This is what will be searched for a :-)";
$string ~= s/:-)/<img src='smile1.gif'>/g;
print $string;

-Aaron



zanardi
journeyman

Feb 13, 2001, 4:42 PM

Post #3 of 5 (381 views)
Re: searching and replacing [In reply to] Can't Post

I know this but I can't do that for what im tring to accomplish

----------------------
Fueled By ZCom


abockover
Deleted

Feb 13, 2001, 6:13 PM

Post #4 of 5 (377 views)
Re: searching and replacing [In reply to] Can't Post

Ok,

It was just a suggestion. But may I ask why?

-Aaron



zanardi
journeyman

Feb 16, 2001, 1:21 PM

Post #5 of 5 (365 views)
Re: searching and replacing [In reply to] Can't Post

Ok I got it to work

im buildling a forum software (signature down below) and I built it so you can add your own custom smilies to the board. that's what it's for :)

----------------------
Fueled By ZCom

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives