Hi Dan (again)

See in-line.

"Dan Muey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Another thing I use a lot is to take form input and build sql queries
based on what is input for instance
> Say I want to search  a table withh twenty columns
> If I have a form with all 20 columns that they can enter something to look
for in each field thay will probably only use a few so I go
>
>
> @params = $cgi->params;
>
> $where = "WHERE";
> Foreach $p(@params) { $where .= " $p=\'$cgi->param($p)\' AND"; }
> $where =~ s/AND$//;
>

The bad news:
Again, not an anonymous reference: you're simply iterating over the @params
array and appending a function of each element to $where. It could be
written

    $where = "WHERE";
    $where .= " $_=\'$cgi->param($_)\' AND" foreach @params;
    $where =~ s/AND$//;

with the same effect.

The good news :)
Once more you have shown me another solution to a basic problem: applying a
separator to a list instead of a terminator. I always code this as something
like

    my $i;
    foreach (@params)
    {
        $where .= ' AND ' if $i++;
        $where .= " $_=\'$cgi->param($_)\'";
    }

but I'd never thought of putting all the terminators on and then removing
the final one.

This is comparable to the practice of initialising a loop counter to -1
before entering a loop whose first action is to increment it, so that the
first value seen by the loop body is zero. Anyhow I'll cease my ramblings
now.

Cheers Dan,

Rob


[snip remainder of Dan's post]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to