CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
perl subroutine

 



ashish_chand
Novice

Apr 10, 2013, 4:28 AM

Post #1 of 3 (400 views)
perl subroutine Can't Post

 
# usage: build_where HASHREF
sub build_where {
my $parms = shift;
my $where = ' WHERE';
my $sql='';
foreach my $key (keys %$parms) {
my $val = $parms->{$key};
next if ( $val eq '' );
if ( $key =~ /^(parm_value|description)$/ ) {
$sql .= "$where $key = :$key";
} elsif ( $key eq 'parm_group_id' && $val =~ ':$' ) { --- what is the use of ':$' what its giving here?
$parms->{$key} = "$val%"; # modify %parms value
$sql .= "$where upper($key) LIKE upper(:$key)";
} elsif ( $key eq 'parm_group_id' && $val =~ ':%$' ) { ----what is the value of ':%$' how its working?
$sql .= "$where upper($key) LIKE upper(:$key)";
} else { $sql .= "$where upper($key) = upper(:$key)"; }
$where = ' AND';
}
return $sql;
}


BillKSmith
Veteran

Apr 10, 2013, 6:26 AM

Post #2 of 3 (392 views)
Re: [ashish_chand] perl subroutine [In reply to] Can't Post


In Reply To
--- what is the use of ':$' what its giving here?


This is a regular expression which tests whether the string $val ends in a colon.


In Reply To
----what is the value of ':%$' how its working?


Similarly, This regex tests whether the string ends in percent, colon.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Apr 10, 2013, 7:26 AM

Post #3 of 3 (389 views)
Re: [ashish_chand] perl subroutine [In reply to] Can't Post

In addition to Bill's info, those 2 parts should have been actual regex patterns, not literal strings.


Code
} elsif ( $key eq 'parm_group_id' && $val =~ /:$/ ) { --- what is the use of ':$' what its giving here? 
$parms->{$key} = "$val%"; # modify %parms value
$sql .= "$where upper($key) LIKE upper(:$key)";
} elsif ( $key eq 'parm_group_id' && $val =~ /:%$/ ) { ----what is the value of ':%$' how its working?


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives