in reply to "Use of uninitialized value" with many variables

Slightly off topic (and not an answer to your question), you really should be using a hash for all of those. Whenver you see a common element (txt_ in this case) in a variable name, that should clue you in. Something like
my %txt = ( AnniversaryDate => '', BithDate => '', EmailAddr => '', FaxNo => '', MobileNo => '', ... );
would be better. If you use a hash, you can also assign to a hash key at any time, so just declare the hash my %txt = (); and then when you want to set a key/value pair, do $txt{key} = "value";

Replies are listed 'Best First'.
Re: Re: "Use of uninitialized value" with many variables
by gwadej (Chaplain) on Oct 06, 2003 at 03:04 UTC
    Although I agree with your suggestion of using a hash in this instance, I would actually code it slightly differently.
    my %txt = map { $_ => '' } qw{AnniversaryDate BirthDate EmailAddr FaxNo MobileMo ... };

    When initializing hash keys all to the same value I've found this idiom helps me make fewer mistakes. It also means less repetitive typing. (For those of us who type slowly, that's important.)

    G. Wade
      my %txt; my @field = qw( AnniversaryDate BirthDate EmailAddr FaxNo MobileNo ... ); @txt{@field} = ('') x @field;
      Update: corrected thinko as per CombatSquirrel's reply.

      Makeshifts last the longest.

        Actually, '' x @field just concatenates @field empty strings and returns that string. This still causes the warning.
        You probably had a typo, intending to say @txt{@field} = ('') x @field;.
        Cheers,
        CombatSquirrel.
        Entropy is the tendency of everything going to hell.

        I still stumble over the hash-slice syntax. I guess I just have to keep working with it.

        Thanks for the reminder.

        G. Wade