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

Hello I am currenltly trying to create a web form where a user will take in information from a log (select the log from a drop down menu in our form) be able to type in the Deal number click get information button and have certain fields show up on the screen. I have the following code:

#!/usr/local/bin/perl use CGI; use CGI qw/:standard :html3 :html4 :netscape :all/; use CGI::Carp 'fatalsToBrowser'; use CGI::Push qw/:standard/; use POSIX qw/strftime/; $query = new CGI; print $query->header; print $query->start_html('Digital Markets Deal Log'); print "<H1>Digital Markets Deal Log</H1>\n"; # Print the first form print $query->startform; $date =(`ls FxDe* | grep -v .gz`); ###################################################################### +############################################# # Variables ###################################################################### +############################################# # file locking (flock): 1=shared, 2=exclusive, 8=unlocked use vars qw/$Time $Dealid $Clientid $CurrencyPair $message $line $name + $date @rows/; my $file ="$date"; my $style; ###################################################################### +############################################# print "What is the Deal ID? ",$query->textfield('name',$name,25); print "<P>Select The Date? ", $query->popup_menu('date',["$date"]), "<P>"; print $query->submit('form_1','Get Deal Info'); print $query->endform; print "<HR>\n"; $query->import_names('Q'); if ($Q::form_1) { open(MESSAGE, "$file") || die "Couldn't open $file: $!\n"; my $locked = flock(MESSAGE,1); unless ($locked) { warn("Couldn't get lock for reading: $!"); alarm(0); close MESSAGE; return undef; } while ($line = <MESSAGE>) { chomp $line; ($Time, $Dealid, $Clientid, $CurrencyPair) = split(/\,/, $line); if $name =~ (/$Dealid/) { unshift(@rows, table({-bgcolor=>'454B74', -border=>'0', -cols=>'2'}, Tr( td({-width=>'25%'}, strong("Time: ") ), td($Time) + ), Tr( td({-width=>'25%'}, strong("Deal ID: ") ), td($Dealid +) ), Tr( td({-width=>'25%'}, strong("Client ID: ")), td($Client +id) ), Tr( td({-width=>'25%'}, strong("Currency Pair: ") ), td($C +urrencyPair)) ), # end table ); } # end if } } $style=<<END; <!-- body { scrollbar-face-color: 454B74; scrollbar-shadow-color: 8792BD; scrollbar-highlight-color: ECECEC; scrollbar-3dlight-color: 000000; scrollbar-darkshadow-color: 000000; scrollbar-track-color: 8792BD; scrollbar-arrow-color: FFFFFF; font-family: tahoma, arial, helvetica, sans-serif; font-size: 12 +px; color: 999999; } td { font-family: tahoma, arial, helvetica, sans-serif; font-size: 12 +px; color: 8792BD; } .td2 { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 13px; color: ececec; } .text { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 10px; color: 8792BD; } .mash { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 13px; color: 8792BD; font-weight: bold; } .mash2 { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 15px; color: 8792BD; font-weight: bold; } a:link { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 11px; color: ececec; } a:visited { font-family: tahoma, arial, helvetica, sans-serif; font-si +ze: 11px; color: ffffff; } a:active { font-family: tahoma, arial, helvetica, sans-serif; font-si +ze: 11px; color: 999999; } a:hover { font-family: tahoma, arial, helvetica, sans-serif; font-size +: 13px; color: 999999; } --> END print header(); print start_html(-title=>'', -bgcolor=>'454B74', -style=>{-code=>$styl +e}), div({-align=>'center'}, # this table displays the entries table({-bgcolor=>'454B74', -border=>'2', -bordercolor=>'8792BD', - +cols=>'2', -width=>'550', -height=>'550'}, [@rows] ), # end of table ), # end of div $locked = flock(MESSAGE,8); close(MESSAGE); exit 0; print $query->end_html;

problem is my if statement in
if $name =~ (/$Dealid/) {
gives me a syntax error. Any ideas of what I am doing wrong ?

2004-04-01 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: If Statement
by dragonchild (Archbishop) on Apr 01, 2005 at 19:11 UTC
    if ( $name =~ /$Dealid/ ) { - you have your opening parenthesis in the wrong place.
      When I put the parenthesis that way, I no longer get syntax error but when I put in my Deal ID into the form and hit submit I don't get my information on the screen instead it acts like a comparison and PERL returns 0 (true) or 1 (false) all that displays to the screen is 1 false. The number is in the log though that I am typing in and it should print to the screen. Any idea what I'm doing wrong ?
        You're not using $DealID = $query->param( MY_PARAM_NAME_HERE );, so how do you expect to read it from the CGI stream?