jptxs has asked for the wisdom of the Perl Monks concerning the following question:

this code:

my $TYPE_QUERY = qq!SELECT APPT_TYPE||'|'||INFO_NEEDED FROM SC_APPT_TY +PE!; my $sth = $dbh->prepare("$TYPE_QUERY") or dienice("709 Couldn't prepare statement: " . $dbh->errstr); $sth->execute() or dienice("713 Couldn't execute statement: " . $sth->errstr); while (my @types = $sth->fetchrow_array()) { foreach my $types (@types) { chomp($types); my ($info, $type) = split "|", $types; print qq!<OPTION VALUE="$type_$info">$type</OPTION>\n!; } }

selecting these rows from an Oracle Database:

Onsite,FULL POC,FULL Phone Walkthru,PHONE Con Call,PHONE FTO,NONE Travel Day,NONE Admin Day,NONE Local Only,NONE Holiday,NONE SC Training,TRAIN

Produce this thing:

Appointment Type:<SELECT NAME="appt_type"><OPTION VALUE="O">n</OPTION> <OPTION VALUE="P">O</OPTION> <OPTION VALUE="P">h</OPTION> <OPTION VALUE="C">o</OPTION> <OPTION VALUE="F">T</OPTION> <OPTION VALUE="T">r</OPTION> <OPTION VALUE="A">d</OPTION> <OPTION VALUE="L">o</OPTION> <OPTION VALUE="H">o</OPTION> <OPTION VALUE="S">C</OPTION> </SELECT>

any ideas?

-- I'm a solipsist, and so is everyone else. (think about it)

Replies are listed 'Best First'.
Re: unexpected result parsing rows from database
by Fastolfe (Vicar) on Sep 21, 2000 at 23:49 UTC
    Your split argument is |, which is regex for "or". Effectively you're telling it to split on <nothing> OR <nothing>, which has the effect of splitting on each character. Since you're not specifying a limit in your 3rd argument to split, you're only catching the first two characters, so that's what you see. To get the effect you're looking for, escape the pipe-character. And I don't mean change the argument to "\|", since all you're doing there is escaping it in the qq{} string. To avoid confusion like this, specify your first split argument as a true regexp: /\|/

    Also, why are you joining the fields in the SQL at all? Why not just SELECT both fields as you would normally, and refer to them as $types[0] and $types[1], respectively?

Re: unexpected result parsing rows from database
by jptxs (Curate) on Sep 21, 2000 at 23:49 UTC

    forgot to escape the '|' - sorry to post too quick

    -- I'm a solipsist, and so is everyone else. (think about it)