in reply to Need help getting correct syntax for "if" statement

  1. You need curly braces around the code to be executed within the conditional.
    if ( index( $fl, '1' ) != -1 ) { $flag = 1 ; } else { $flag = 0 ; }
  2. There are many ways to do this. Here's a few, in the order I prefer them:

    1. Use the CGI module from CPAN.
      print $query->hidden( -name => 'hidden_name', -default => $ph );
    2. Use printf.
      printf '<input type="hidden" name="phone_number" value="%s">', $ph ;
    3. Use interpolation.
      print "<input type=\"hidden\" name=\"phone_number\" value=\"$ph\">" ;

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Replies are listed 'Best First'.
Re: Re: Correct Syntax
by Juerd (Abbot) on Aug 08, 2002 at 22:47 UTC

    print "<input type=\"hidden\" name=\"phone_number\" value=\"$ph\">" ;

    perlop.

    print qq[<input type="hidden" name="phone_number" value="$ph">];

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: Re: Correct Syntax
by jdawes (Novice) on Aug 08, 2002 at 22:57 UTC
    You'll probably laugh but
    How do I embed that in the form
    if ($ag eq "*********") {print " <form action=FormMail.pl method=post name=accept_estimate_cost target= +_self id=accept_estimate_cost> <input type=hidden name=job_number value= > {print qq[<input type="hidden" name="phone_number" value="$ph">]; <input type=hidden name=phone_number value= $ph >

      You're *guessing* syntax again. That will not work. Not today, not ever. If you have to ask for help for things like this, stop asking and start *learning*. You do not learn a language only by trying something, hoping the receiving end will be able to decrypt your illogical grammar. You will have to read documentation *before* you start programming. perlintro is a good start, but don't stop there.

      Sane programming cannot be done with the copy/paste function.

      If you're not willing to learn basic syntax rules, just please stop asking these stupid questions.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

      If you mean "in the form" in the "right in the HTML" sense, you may need to use something like Text::Template to put this kind of functionality in there.

      If you mean in the context of CGI, then the idea is simply to output bits of HTML, one after the other. In this case, you're merely printing a part conditionally.