Link to home
Start Free TrialLog in
Avatar of ItsMe
ItsMe

asked on

pattern matching problem

Hi ! I'm new in perl. Currently I'm developing a small online shop system. The script reads from a plain text database each line as one product. if you order a product, the line index is written into a hidden field and added to the other indexes in this field. if you want to remove an item I just replace the line index by ''. To prevent matching errors I'm adding '#'
before and after the index. now I've got a problem: If the user want to add the same product two times, my script doesn't catch this:
$art is the value of the Button (can be delete, too)
$artikel is the value of the hidden field where all the indexes are in
$artindex is the index to add, or to delete or not to add

     if ($art eq 'Bestellen')
                              {
                                     $temp  = "\#$artindex\#";
                                     if ($temp =~ $artikel) #<--- This doesn't work !
                                                                     {
                                                                            $artindex =~ s/\#//g;
                                                                            $temp = &GetEntry($artindex,1);
                                                                            &info ("Folgender Artikel wurde bereits von Ihnen in den Warenkorb gelegt\:\<br\>\"$temp\"");
                                                                     }
                                                                       else
                                                                     {
                                                                       $artikel = "$artikel\;\#$artindex\#";
                                                                          }
                              };

I just want to check, if #$artindex# is already in $artikel, why doesn't it work ???

regards
ItsMe
Avatar of prakashk021799
prakashk021799

The comparison should be:

if ($artikel =~ m/$temp/) {
Avatar of ItsMe

ASKER

Hi !
I already tried this but it didn't work ! And: If one of the variables is empty, does it match or not ?
ASKER CERTIFIED SOLUTION
Avatar of prakashk021799
prakashk021799

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to delimit $artindex by semi-colon (as you seem to be doing in your code), change the last line (the one above the closing brace) to:

    $artikel .= ";\#$artindex\#';
Avatar of ozo
Does $artindex contain search metacharacters?
Avatar of ItsMe

ASKER

good job ! thank you very much ! i just had to flip the vars. as you did above. perhaps you know where i can find a manual about shop-structures or something else ... i only need a good strategy even I think mine isn't that bad, what do you think ???

regards
ItsMe
Avatar of ItsMe

ASKER

what are search metacarachters ?