Proper structure:

if ($...) {} # UNLESS NOT TO BE USED HERE
elsif {}
else {}

JMPO... (Just My Perl Opinion)

On 2/11/06, Ron Smith <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
>   I've got a CGI script that takes two strings and sorts them in order,
> then prints them. The problem is I don't want nulls or numbers entered. I
> think I've got the "null" end of it right, but I'd also like to error-out
> any numbers entered. Take a look at the "unless" line.
>
>   ...any suggestions??
>
>   #!E:/www/perl/bin/perl.exe
>   use strict;
> use warnings;
> use CGI qw( :standard );
> use CGI::Carp qw( fatalsToBrowser );
>
>   print header();
>
>   my $firstString = param( "textfield" );
> my $secondString = param( "textfield2" );
>
>   my @list = sort ( $firstString, $secondString );
>
>   unless ( $firstString && $secondString && /\w+/ ) {
> print<<HTML;
> <html>
> <body>
> <p> This page takes two strings from the user and prints them in
> alphabetical order. If they are equal, they will print on separate lines.
> </p>
> <form name="form1" id="form1" method="post"
> action="../webroot/cgi-bin/pg59ex2.11SortStrings.pl">
>   <table width="341" border="0">
>     <tr>
>       <td width="181"><div align="right">Enter your first string:
> </div></td>
>       <td width="144"><input type="text" name="textfield" /></td>
>     </tr>
>     <tr>
>       <td><div align="right">Enter your second string: </div></td>
>       <td><input type="text" name="textfield2" /></td>
>     </tr>
>     <tr>
>       <td colspan="2"><div align="center"><font color="red"> Please, enter
> two words! </font></div></td></td>
>     </tr>
>     <tr>
>       <td colspan="2"><div align="center"><a
> href="/pg59ex2.11SortStrings.html"> Click here to go back </a></div></td>
>     </tr>
>   </table>
> </form>
> <p></p>
> </body>
> </html>
> HTML
> }
>   elsif ( $firstString eq $secondString ) {
> print<<HTML;
> <html>
> <body>
> <p>This page takes two strings from the user and prints them in
> alphabetical order. If they are equal, they will print on separate
> lines.</p>
> <form name="form1" id="form1" method="post"
> action="../webroot/cgi-bin/pg59ex2.11SortStrings.pl">
>   <table width="341" border="0">
>     <tr>
>       <td width="181"><div align="right">Enter your first string:
> </div></td>
>       <td width="144"><input type="text" name="textfield" /></td>
>     </tr>
>     <tr>
>       <td><div align="right">Enter your second string: </div></td>
>       <td><input type="text" name="textfield2" /></td>
>     </tr>
>     <tr>
>       <td colspan="2"><div align="center"> $firstString<br>$secondString
> </div></td></td>
>     </tr>
>     <tr>
>       <td colspan="2"><div align="center"><a
> href="/pg59ex2.11SortStrings.html"> Click here to go back </a></div></td>
>     </tr>
>   </table>
> </form>
> <p></p>
> </body>
> </html>
> HTML
> }
>   else {
> print<<HTML;
> <html>
> <body>
> <p>This page takes two strings from the user and prints them in
> alphabetical order. If they are equal, they will print on separate
> lines.</p>
> <form name="form1" id="form1" method="post" action="">
>   <table width="341" border="0">
>     <tr>
>       <td width="181"><div align="right">Enter your first string:
> </div></td>
>       <td width="144"><input type="text" name="textfield" /></td>
>     </tr>
>     <tr>
>       <td><div align="right">Enter your second string: </div></td>
>       <td><input type="text" name="textfield2" /></td>
>     </tr>
>     <tr>
>       <td colspan="2"><div align="center"> @list </div></td>
>     </tr>
>     <tr>
>    <td colspan="2"><div align="center"><a
> href="/pg59ex2.11SortStrings.html"> Click here to go back </a></div></td>
>     </tr>
>   </table>
> </form>
> <p></p>
> </body>
> </html>
> HTML
> }
>
>
> Ron Smith
> [EMAIL PROTECTED]
>

Reply via email to