Perl Hash in String konvertieren - Problem mit uninitialisierten Variablen

Bastian Schern <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
Hallo *,

ich wÃŒrde gerne eine Perl Hash in einen String konvertieren. Das mache 
ich derzeit so:

--- snip ---
#!/usr/bin/perl -w
use strict;

[...]

sub hash2string( )
{
     my( $hash ) = @_;
     my $string = "";

     my @keys = sort( keys( %$hash ) );
     foreach my $key ( @keys ) {
         my $value = $hash->{ $key };
         if( $value eq '' ) {
             $value = "";
         } elsif( !$value ) {
             $value = "<NULL>";
         }
         $string = $string . sprintf( "\t%-15s => %s\n", $key, $value );
     }

     return substr( $string, 0, length( $string ) - 1 );
}
--- snap ---

Jetzt kommt es leider öfter mal vor, dass $value nicht initialisiert ist 
und ich erhalte dann folgende Fehlermeldung:
Use of uninitialized value in string eq at ./convert.pl line 555, 
<STDIN> line 1.

Wie kann fehlerfrei ÃŒberprÃŒfen ob $value ein leerer String ist oder 
nicht initialisiert wurde?

Viele GrÌße
	Bastian

-- 
Um die Liste abzubestellen, schicken Sie eine Mail an:
    [email protected]
Um eine Liste aller verfÃŒgbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.