Quite aside from the if issue, that code smells bad. There are many techniques that will will clean it up, but the end point is to move the HTML stuff out of the source altogether into a template. The following code generates the template file as a convenience for testing (just run the script). Usually the "create file" stuff isn't required!
#!/usr/bin/perl use strict; use warnings; use HTML::Template; # Create a test template file my $tmplFileName = "template.htmlt"; open my $tmplOut, '>', $tmplFileName or die "Can't create $tmplFileNam +e: $!\n"; print $tmplOut <<TMPL; Content-type:text/html <html> <head> <title>Account/title> </head> <body> <h2><TMPL_VAR message /></h2> </body> </html> TMPL close $tmplOut; # "production" code my $tmpl = HTML::Template->new(filename => $tmplFileName); my $user = 'Mr. Foo'; if (1) { $tmpl->param(message => "Hello $user, your account - ready"); print $tmpl->output(); exit 0; } else { $tmpl->param(message => "Your user/pin incorrect - Use correct in +put"); print $tmpl->output(); }
Prints:
Content-type:text/html <html> <head> <title>Account/title> </head> <body> <h2>Hello Mr. Foo, your account - ready</h2> </body> </html>
Note too that the test file content is generated using a HEREDOC to inline the file contents. If you really need to include a fragment of HTML in your source code that's a much nicer way to do it than multiple print statements!
Also note the use of strictures (use strict; use warnings;) and the open statement using lexical file handle and result testing.
In reply to Re: perl if statement
by GrandFather
in thread perl if statement
by Drsin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |