Advertisement

06.23.2004 at 12:27PM PDT, ID: 21035867
[x]
Attachment Details

Why is this sub only returning one array member?

Asked by GessWurker in Perl Programming Language

Tags: buildwpquery, multipleentry

I've got a sub routine that spits out a nice xml query string. I'm trying to add another sub to deal with multiple field entries. So that, for instance, if someone enter one|two|three in my multipleEntry field (i.e., <input type="text" name="multipleEntry" value="one|two|three">, I end up with:

      <multipleEntry><![CDATA[one]]></multipleEntry>
      <multipleEntry><![CDATA[two]]></multipleEntry>
      <multipleEntry><![CDATA[three]]></multipleEntry>

Here's what I've done. Unfortunately, it's only returning  the first member,     <multipleEntry><![CDATA[one]]></multipleEntry>, instead of all three. Please show me the error.

sub buildWpQuery {
    my $xml = "<?xml version=\"1.0\" ?>\n" .
                   "<Query xmlns=\"http://www.inmagic.com/webpublisher/query\">\n" .
                   "<AC>insert</AC>\n" .
                   "<TN>ConfFeedback</TN>\n" .
                   "<KeyFields>\n" .
                   "   <KeyField>UniqueID</KeyField>\n" .
                   "</KeyFields>\n" .
                   "<Recordset>\n" .
                   "   <Record>\n" .
                   "      <UniqueID><![CDATA[".$query->param("UniqueID")."]]></UniqueID>\n" .
                   "      <FirstName><![CDATA[".$query->param("firstName")."]]></FirstName>\n" .
                   "      <LastName><![CDATA[".$query->param("lastName")."]]></LastName>\n" .
                   "      <Email><![CDATA[".$query->param("email")."]]></Email>\n" .
                   "      <Feedback><![CDATA[".$query->param("feedback")."]]></Feedback>\n" .
                   "      <Status><![CDATA[".$query->param("Status")."]]></Status>\n".
                          makeMultiple($query->param("makeMultiple"));

        $xml .=    "   </Record>\n</Recordset>\n</Query>";
    return $xml;

}

sub makeMultiple {
   my $string = shift;
   my @members = split(/\|/,$string);

foreach my $mM(@members) {
       return  "      <MultipleEntry><![CDATA[".$mM."]]></MultipleEntry>\n"}

}

Start Free Trial
[+][-]06.23.2004 at 12:48PM PDT, ID: 11382772

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: buildwpquery, multipleentry
Sign Up Now!
Solution Provided By: simon_holroyd
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.23.2004 at 12:58PM PDT, ID: 11382839

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32