On Thu, Jun 14, 2001 at 11:10:43PM -0500, [EMAIL PROTECTED] wrote:
> > Format to taste, of course. Your checks on $add_alias, $add_destination,
> > and $selection should also probably be checks for defined'ness, not truth.
> > 0 is false, but, according to your definition of what $add_alias should
> > contain, is also a valid value.
>
> i am not sure what you mean here. i am trying to check whether
> or not anything was filled in for these fields. i am grabbing
> $add_alias from the hash parsed by a form parsing subroutine.
> (the data is coming from a web page form)
When you say:
if ($add_alias) { ... }
You are testing to see if $add_alias is true. If $add_alias = 0, the block
won't be executed. 0 may be a valid value for $add_alias to have. If this
is the case, you probably should be testing to make sure $add_alias is
defined, meaning it has some value other than the special undef value. You
test for this using the defined operator, perldoc -f defined.
> > Also, in your current code you don't do any checks on your calls, such as
> > your open and rename calls. You should always check open, and usually check
> > rename.
>
> i am not certain what you mean by 'checks on calls' either.
> point me in the right direction?
Both open and rename return true on success, false on failure. The typical
idiom is:
open(FILE, $filename) || die("Unable to open filename \"$filename\": $!\n");
What this means is that, if the file couldn't be opened, the script dies
with an appropriate error message. Review perldoc -f open, perldoc
perlopentut, and perldoc perlvar (for $!).
The above descriptions of truth, definedness, and checking open should have
been covered in your learning material. You do have learning material, yes?
If you don't, or if you do and it didn't cover these topics, consider
purchasing _Learning Perl_ by Randal Schwartz, or _Beginning Perl_ by Simon
Cozens.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--