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
ItsMeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prakashk021799Commented:
The comparison should be:

if ($artikel =~ m/$temp/) {
0
ItsMeAuthor Commented:
Hi !
I already tried this but it didn't work ! And: If one of the variables is empty, does it match or not ?
0
prakashk021799Commented:
> If one of the variables is empty, does it match or not ?

The general syntax for pattern matching is (without any modifiers):

$string =~ m/$pattern/;

If $string is empty, then result of the matching is false.
If $pattern is empty, then result of the matching is true.

Change the code so that you will search the $artikel string only if it is non-empty.

if ($artikel and $artikel =~ m/\#$artindex\#/) {
    # $artindex is already in the $artikel
    # do whatever you want to do
} else {
    # add $artindex to $artikel
    $artikel .= "\#$artindex\#';
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

prakashk021799Commented:
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\#';
0
ozoCommented:
Does $artindex contain search metacharacters?
0
ItsMeAuthor Commented:
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
0
ItsMeAuthor Commented:
what are search metacarachters ?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.