Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 2nd, 2001, 03:34 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Complex pattern matching

I need help... I'm writing a subroutine to convert html to BBcode... and it's not quite working...

Since it contains BBcode, I can't post the code directally here... however I will post a link to it.

http://gms.uoe.org/html2bb.txt

Anyone that can help, please do!

Reply With Quote
  #2  
Old June 4th, 2001, 10:04 AM
iansmith iansmith is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Boston, MA
Posts: 0 iansmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What you need to do is change your thinking a bit.

You are thinking of the html and BB tags as one item, but you can think of them as seperate tags.

Instead of making a list where each element contains the start and end tag, make a list that has start and end tags as seperate elements. That way you can deal with nested html code without extra coding.

--
Ian

Reply With Quote
  #3  
Old June 4th, 2001, 02:00 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes well

I still need to be able to grab the URLs from <A> tags and perhaps the colors from <FONT> etc... so I still need to be able to capture + print...

Reply With Quote
  #4  
Old June 4th, 2001, 04:49 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
http://expert.cc.purdue.edu/~coultejk/temp/tmp.txt

This is obviously untested code here (I just wrote it, and havn't tried it), but it should give you an idea of where you can go with it.

Reply With Quote
  #5  
Old June 4th, 2001, 06:22 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

I was hopeing to be able to keep them in the same hash, but I guess I'll need to pull them out.

I read in Programming Perl something that led me to believe that I could do that sucessfully using qr//

So... umm... was I way off, or just not using it right?

Is there a way to keep them in the hash listing and still do what I want it to do?

Reply With Quote
  #6  
Old June 5th, 2001, 08:27 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Ah HA!?

Ok, I think this SHOULD work, but it doesn't... the hash remains the same as it is in the above link

Code:
   foreach $KEY (keys %TAGLIST){
      while($text =~ m/$KEY/g){
         local $replace = '';
         eval(qq~\$replace = "$TAGLIST{$KEY}"~);
         die "$@ \nFailed String:$TAGLIST{$KEY}" if($@);
         $text =~ s/$&/$replace/;
      }
   }


I now get this error:

Search pattern not terminated at (eval 6) line 1

Failed String:[U-RL=$1]$2[/U-RL] at testhtml.cgi line 31 (Remove the - in between U and RL)


I know I'm on the right track.. but I'm missing something...

I sucessfully tested the majority of it with a seperate program

Code:
$TAGLIST = 'Hi $KEY';
$KEY = 'John';

eval("\$prep = \"$TAGLIST\"");
die $@ if($@);

print $prep;



The one I just listed works... so what did I miss?

Reply With Quote
  #7  
Old June 5th, 2001, 09:41 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb SOLVED!

I DID IT!

I solved my problem... and it was so simple!

Code:
foreach $KEY (keys %TAGLIST){
   eval("\$text =~ s/$KEY/$TAGLIST{$KEY}/gis;");
   die "$@ \n Failed String: $TAGLIST{$KEY}" if($@);
}



YEY!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Complex pattern matching


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway