genyded has asked for the wisdom of the Perl Monks concerning the following question:

I have one warning...

"Use of uninitialized value in hash element at C:/Perl/site/lib/Locale/SubCountry.pm line 439, <DATA> line 15048."

It will not supress not matter what I do. I've tried perldiag and carping confess to no avail. It's coming from one of the packages included with "use" but, I have no idead which one. Here is the code...

use warnings; #use diagnostics; <-DID NOT GIVE ANY USEFUL INFO #use Carp qw( confess ); <-BLOWS UP THE PERL CI # $SIG{__WARN__} = \&confess; #THIS SUPPRESSES ALL WARNINGS EXCEPT THE ONE ABOVE WHICH PRINTS OUT AT + THE BEGINING OF THE OUTPUT AND IS DRVING ME NUTS!!! local $SIG{__WARN__}=sub{}; use Data::Type qw(:all +W3C); #used to valdiate data types of values use DBD::ODBC; #sql support use File::Find; #file and directory recursion use Log::Log4perl; #log file and vebosity control use Net::Telnet; #telnet support use Switch; #perl switch and case support use XML::Simple; #xml input, output & parsing use Tie::Handle::CSV; #csv support
Any ideas on how to keep this bugger from printing to STDERR??? Here is the begining of the output...

Use of uninitialized value in hash element at C:/Perl/site/lib/Locale/ +SubCountry.pm line 439, <DATA> line 15048. [2007/10/06 06:47:32-INFO]: Establishing Telnet connection to host... [2007/10/06 06:47:32-INFO]: Succesfully connected to host via Telnet ... ...
TIA!

Replies are listed 'Best First'.
Re: Warning will not supresss
by TGI (Parson) on Oct 06, 2007 at 21:43 UTC

    The entry for the Shariff Kabunsuan region of the PHILIPPINES does not have a code. Apparently the ISO 3166.2 codes do not reflect recent changes in Philipino government structure.

    Since the data set is accurate, one must then conclude that the code that parses the data set is in error. The code makes the assumption that any 'subcountry' will have both a 'name' and a 'code'.

    I think the right thing to do is to patch the parsing logic to match the current coding style. The warning is correct, there is a problem with the code.

    Submit a bug report and possibly a patch to the author.

    I've made a feeble stab at fixing the code, but I don't know enough about localization standards to know if my implementation is correct.

    Here is the relevant section of the original code, from around line 439:

    # Insert into doubly indexed hash, grouped by country for ISO 3166-2 # codes. One hash is keyed by abbreviation and one by full name. Altho +ugh # data is duplicated, this provides the fastest lookup and simplest co +de. $::subcountry_lookup{$country_name}{_code_keyed}{$sub_country_code} = +$sub_country_name; $::subcountry_lookup{$country_name}{_full_name_keyed}{$sub_country_nam +e} = $sub_country_code; if ( $category ) { $::subcountry_lookup{$country_name}{$sub_country_code}{_category} += $category; } if ( $regional_division ) { $::subcountry_lookup{$country_name}{$sub_country_code}{_regional_d +ivision} = $regional_division; } if ( $FIPS_code ) { # Insert into doubly indexed hash, grouped by country for FIPS 10- +4 codes $::subcountry_lookup{$country_name}{_FIPS10_4_code_keyed}{$FIPS_co +de} = $sub_country_code; $::subcountry_lookup{$country_name}{_ISO3166_2_code_keyed}{$sub_co +untry_code} = $FIPS_code; }

    Here are my untested modifications:

    # Insert into doubly indexed hash, grouped by country for ISO 3166-2 # codes. One hash is keyed by abbreviation and one by full name. Altho +ugh # data is duplicated, this provides the fastest lookup and simplest co +de. $::subcountry_lookup{$country_name}{_full_name_keyed}{$sub_country_nam +e} = $sub_country_code || 'UNDEFINED'; # These items all depend on a sub_country_code being set. if ( $sub_country_code ) { $::subcountry_lookup{$country_name}{_code_keyed}{$sub_country_code +} = $sub_country_name; if ( $category ) { $::subcountry_lookup{$country_name}{$sub_country_code}{_catego +ry} = $category; } if ( $regional_division ) { $::subcountry_lookup{$country_name}{$sub_country_code}{_region +al_division} = $regional_division; } if ( $FIPS_code ) { # Insert into doubly indexed hash, grouped by country for FIPS + 10-4 codes $::subcountry_lookup{$country_name}{_FIPS10_4_code_keyed}{$FIP +S_code} = $sub_country_code; $::subcountry_lookup{$country_name}{_ISO3166_2_code_keyed}{$su +b_country_code} = $FIPS_code; } }


    TGI says moo

Re: Warning will not supresss
by codeacrobat (Chaplain) on Oct 06, 2007 at 14:32 UTC
    Hi, You can fix Locale::SubCountry by encapsulating line 439 in a no warning block.
    { local $^W=0; $::subcountry_lookup{$country_name}{_code_keyed}{$sub_country_code} = +$sub_country_name; $::subcountry_lookup{$country_name}{_full_name_keyed}{$sub_country_nam +e} = $sub_country_code; }
Re: Warning will not supresss
by SFLEX (Chaplain) on Oct 06, 2007 at 13:50 UTC
    you can try this to remove the error.
    $SIG{__WARN__} = sub { my $wn = shift; return if $wn =~ /Use of uninitialized value/i; #Most annoying warn $wn; };

    Good Luck^^

    *Edited if you still have problems try this.
    BEGIN { $SIG{__WARN__} = sub { my $wn = shift; return if $wn =~ /Use of uninitialized value/i; #Most annoying warn $wn; }; }
Re: Warning will not supresss (BEGIN, -X)
by tye (Sage) on Oct 06, 2007 at 21:28 UTC

    Since your local $SIG{__WARN__}= sub {}; doesn't suppress that one warning, I can only conclude that the warning is happening before that line is run or after the enclosing scope is left (likely it is happening when you use that module, though I uncharacteristically haven't looked at the source code for that module to determine if that line number gets run at use time -- use statements get run when they are compiled, which will be before your __WARN__ override gets run). So switch it to this:

    BEGIN { $SIG{__WARN__}= sub { }; }

    and I expect you can adjust it after that to only suppress the warnings that you want suppressed.

    There is also #/usr/bin/perl -X which just disables all warnings.

    - tye