Hi all,

First off, thanks Bill for the help you gave me on my last problem.  Really apreciated!

Now for a new one...

I have tokenized string that comes from a database.  an example of one is:

O{bTyp | S{WCS-STD}bUsr | S{GONZALO}bUid | S{REP.352637}sId | A{}sNme | S{}sUrl | S{}sLbl | S{}sCok | S{}mMsg | S{Welcome to the customer service area of our web site.}fAct | S{}fTyp | S{}fKey | S{}fVal | S{}}

This is contained on one field returned by DBI. What I'd like to do is take a hacket to it and just be left with:

"GONZALO" and "Welcome to the customer service area of our web site."

I have written code that will do that (included below) but it is not very portable and it's kinda lengthy for being perl.. 

What would be a heaven sent is if I could use variables in a regular expression, something like $szVal =~ /$szPattern1(.*)$szPattern2/ but I don't see anywhere I can do that..  I have read the O'Reilly Mastering Regexes book cover to cover, no hints..

Does anyone know a better way to extract what I need?

Here is the code that I have...  It's working...  but I'm only looking for the specified values, if I have to look for something else within the string, this will not cut it...

<!-- Begin -->
# sample database result
my $Content = "O{bTyp | S{WCS-STD}bUsr | S{GONZALO}bUid |"      
        . "S{REP.352637}sId | A{}sNme | S{}sUrl | S{}sLbl | S{}sCok | " 
        . "S{}mMsg | S{Welcome to the customer service area of our web "
        . "site.}fAct | S{}fTyp | S{}fKey | S{}fVal | S{}}";

# begin hail mary code
if ($Content =~ /^O\{fKey/)
{
        $Content =~ s/O\{fKey\s\|\sS\{\}\sfAct\s\|\sS\{\}\ssUrl\s\|\sS\{\}\ssId\s\|\sA\{\}\ssNme\s\|\sS\{\}\sbUid\s\|\sS\{//;
        $Content =~ s/\}\sbTyp\s\|\sS\{WCS-STD\}\sfTyp\s\|\sS\{\}\sbUsr\s\|\sS\{/\n\ \ /;
        $Content =~ s/\}\sfVal\s\|\sS\{\}\smMsg\s\|\sS\{/\ /;
        $Content =~ s/\}\ssLbl\s\|\sS\{\}\s\}/\n\n/;
}
elsif ($Content =~ /^O\{bTyp\s\|\sS\{WCS\-STD\}/)
{
        $Content =~ s/O\{bTyp\s\|\sS\{WCS\-STD\}bUsr\s\|\sS\{//;
        $Content =~ s/\}bUid\s\|\sS\{(REP|CUST)\.\d*\}sId\s\|\sA\{(\s*\w*\d*\{*\}*)*\}sNme\s\|\sS\{/\n/;
        $Content =~ s/\}sUrl\s\|\sS\{/\ /;
        $Content =~ s/\}sLbl\s\|\sS\{/\ /;
        $Content =~ s/\}sCok\s\|\sS\{\}mMsg\s\|\sS\{/\ /;
        $Content =~ s/\}fAct\s\|\sS\{\}fTyp\s\|\sS\{\}fKey\s\|\sS\{\}fVal\s\|\sS\{\}\}/\n\n/;
}
elsif ($Content =~ /^O\{bTyp\s\|\sS\{WCS\-FRM\}/)
{
        $Content =~ s/\w*|\{|\}|\:|\.|\?|\@|\/*|\s*|\-|\|*//g;
}
elsif ($Content =~ /^N/)
{
$Content =~ s/N\{\}//;
}
elsif ($Content =~ /^O\{bUid\s\|\sS\{WCS\.SYSTEM\}/)
{
$Content =~ s/O\{bUid\s\|\sS\{WCS\.SYSTEM\}\sbTyp\s\|\sS\{WCS\-HUP\}\sbUsr\s\|\sS\{\}\s\}/WCS\.SYSTEM\n\ \ \ \[\*\*\*End\sof\sTransc
ript\*\*\*\]\n/;
}
$Content =~ s/\^60|\^27/\`/g;

# print out results
print $Content;


<!-- end -->

Thanks a lot for any help that may come my way... _______________________________________________ Perl-Win32-Web mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to