On Fri, 8 Jun 2001 [EMAIL PROTECTED] wrote:

> > You get this warning because $action is undefined. Comparing undefined value
> > with something is usually unwanted, so it produces a warning.
> >
> > You could rewrite it to:
> > if (defined($action) && ($action eq 'add')) {
> >
> > or assign something meaningful to $action before you use it.
> >
> >
>
>       why is $action undefined? i use my $action; earlier in the script
>       and i thought that the statement $action = $formdata{action};
>       would take care of assigning a value to $action so that it would
>       not be undefined.

Declaration and definition are not the same thing.  A declaration says to
the program "this variable will be used", whereas a definition assigns a
value to the variable:

my $action;  #a variable declaration
$action = 0; #a declaration and a definition

If you use a variable that has no value, you will get an error.  Since
Perl does not require declaration before use, it's easy to forget to
define a variable before using it.  In your case, you are comparing the
value of $action to the string 'add', but no value has been assigned to
$action until *after* the comparison.

-- Brett

Brett W. McCoy
Software Engineer
Broadsoft, Inc.
240-364-5225
[EMAIL PROTECTED]

Reply via email to