First off, while you showed a lot of code, you may have left out some relevant things, like: "What does 'clean_sql()' do, exactly?" and "What is in @_ when this thing runs?"

I actually expect that this line is a mistake, or at least the assignment to @_ is unnecessary:

my ($sql_bb_activity_code,...,$sql_bb_region_code)=@_;
Apart from that, some judicious use of arrays and hashes would make the code a lot shorter, more readable, and probably easier to maintain. Here's one way (which doesn't go as far as it could in terms of organizing things into data structures, but it goes a long way in the right direction), to set up the sql statement:
use strict; # I assume your app already has this somewhere ##################### # DECLARE VARIABLES # ##################### my $count = 0; # Count the number of rows my @grab_results = (); # Array containing results my $statement; # sql statement my @error = (); # Array to store any DB errors my $connection_status; # Tells us whether we connected to a DB or not ################## # CGI PARAMETERS # ################## my %bb; my @fldnames = qw(emp_user_name bb_activity_code bb_model bb_pin bb_phone bb_imei_esn_doc bb_status bb_region_c +ode); my @fldops = qw(LIKE LIKE = LIKE LIKE LIKE = =); $bb{$_} = clean_sql(param($_)) for ( @fldnames ); ########################## # Generate SQL statement # ########################## my $whereclause = ''; if ( $bb{emp_user_name} ne '*') { my @conditions = (); for my $i ( 0 .. $#fldnames ) { my $fname = $fldnames[$i]; if ( $bb{$fname} ne '' ) { push @conditions, "$fname $fldops[$i] " . (( $fldops[$i] eq '=' ) ? $bb{$fname} : "\%$bb{$fname +}\%" ); } } exit if ( @conditions == 0 ); $whereclause = 'WHERE ' . join( ' AND ', @conditions ); } $statement = 'SELECT ' . join( ',', 'bb_id', @fldnames ) . " FROM blackberry $whereclause ORDER BY emp_user_name"; ################################################## # Connect to the database and send sql statement # ################################################## # ...
That much, with your later stuff tacked on, passes "perl -cw", though it has not been tested in any way beyond that.

As for your later observations about how the script hangs with the sql statement that has no "WHERE" clause, you might need to make up an ad-hoc perl script that you can run from the command line to connect to the database and just run that one query and print output to the screen, to see what happens.


In reply to Re: Search breaks based on search string by graff
in thread Search breaks based on search string by Kiko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.