in reply to uninitialized variables

With the function defined, you can test if a variable is defined...

unless (defined $variable) { # if undefined $variable = 0; # set to standard value }
or shorter:
defined $variable or $variable = 0;
or:
$variable = 0 unless defined $variable;

Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Replies are listed 'Best First'.
Re: Re: uninitialized variables
by fuzzyping (Chaplain) on Mar 28, 2002 at 23:22 UTC
      > $variable ||=0;

      This will work as long as $variable is not an empty string. I think, in perl6 there will be something like
      $variable //= 0;
      just for cases like that.

      Best regards,
      perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Re: Re: uninitialized variables
by caitsdeo (Novice) on Mar 28, 2002 at 17:13 UTC
    Checking for undefined values looks like the way to go. I'm going to add this to my code. Thank you all for the quick responce.