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

You can set all these defined and empty with this,

my ($txt_AnniversaryDate, $txt_BithDate, $txt_EmailAddr, $txt_FaxNo, $txt_MobileNo, $txt_Name, $txt_PhoneNo, $txt_PhysicalAddress, $txt_PhysicalCode, $txt_PhysicalCountry, $txt_PhysicalTown, $txt_PostalAddress, $txt_PostalCode, $txt_PostalCountry, $txt_PostalTown, $txt_Sex, $txt_Surname) = ('') x 17;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: "Use of uninitialized value" with many variables
by tilly (Archbishop) on Oct 06, 2003 at 02:39 UTC
    You don't even have to count how many there are of them:
    $_ = '' for my ( $txt_AnniversaryDate, $txt_BithDate, $txt_EmailAddr, $txt_FaxNo, $txt_MobileNo, $txt_Name, $txt_PhoneNo, $txt_PhysicalAddress, $txt_PhysicalCode, $txt_PhysicalCountry, $txt_PhysicalTown, $txt_PostalAddress, $txt_PostalCode, $txt_PostalCountry, $txt_PostalTown, $txt_Sex, $txt_Surname );
    (Trick borrowed from TheDamian.)

    UPDATE: I had a typo noticed by atcroft.

      Or use map in void context, which as of Perl 5.8.1 is no longer "costly" (inefficient). As of v5.8.1, map in void context doesn't create a list that just gets thrown away. Hense:

      map { $_ = "" } ($txt_AnniversaryDate, $txt_BithDate, $txt_EmailAddr, $txt_FaxNo, $txt_MobileNo, $txt_Name, $txt_PhoneNo, $txt_PhysicalAddress, $txt_PhysicalCode, $txt_PhysicalCountry, $txt_PhysicalTown, $txt_PostalAddress, $txt_PostalCode, $txt_PostalCountry, $txt_PostalTown, $txt_Sex, $txt_Surname );

      Anything but pretty.


      Dave


      "If I had my life to do over again, I'd be a plumber." -- Albert Einstein