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

I ran in following error message:

Use of uninitialized value in print at versuch.pl line 275, <GEN2> line 5

This message is generated by a print of a variable assigned a couple of lines above. It seems to me that no more variables could be assigned. What happend ?? (: ChFa
#------- Standard Bibliotheken --------------- use FileHandle; use FindBin; use lib $FindBin::Bin; use lib "$FindBin::Bin/../lib"; #-------- Pfade ----------------------------- #--- Programm: my $BIN_PATH = $FindBin::Bin; my $ROOT_PATH = $BIN_PATH; $ROOT_PATH =~ s/bin//; my $LOG_PATH = $ROOT_PATH . "log/"; my $LIB_PATH = $ROOT_PATH . "lib/"; my $TMP_PATH = $ROOT_PATH . "tmp/"; #------- Programm Bibliotheken ------------ use dump_paras; ... read_file( $DumpFile); #-- sub read_file { #------ Eingabe my $FileName = shift; #------ Rueckgabe my ( %GeneralInfo, %InterfaceInfo ); #------ Konstanten --------- my $INPUT = new FileHandle; my $NotNamed = "n.n."; #------ Variablen my ( $SNMP_Support,$IF_Nr, $OID_ref, $OidEnterpriseMatch); #------ Fehlerbehandlung my $Success = 0; #------ Bearbeitung open $INPUT, $FileName or die $!; while( <$INPUT> ) { my $IfDescDesc= $Interface[$i_iide]; /^($Ref2General->[$i_ghos])/ and do { chomp(); .....(some filtering stuff) /^($Ref2General->[$i_goid])/i and do { my $Key; my $Unkown = "Unkown"; # <--- Assignment 4 LINE 275 $OidEnterpriseMatch = $FALSE; chomp(); s/^($Ref2General->[$i_goid]:\s*)//; /^($StartOfOID)/ and do { s/(.\d.)(\d*)$//; print $Unknown, "\n"; # <---- LINE 275!! $GeneralInfo{$Ref2General->[$i_goid]}=$2; ..the Module normaly used 4 assignment: package dump_paras; use Exporter; @ISA = qw(Exporter); @EXPORT = qw( $i_ghos $i_gsta $i_gdes $i_gloc $i_gsnm $i_gnov $i_gn +oa $i_gnoi $i_goid $i_iina $i_iide $i_ista $i_iipa $i_ii +pm $i_iinu $i_iity $i_iist $Ref2General $Ref2Interface $Ref2Networkers $Ref2NetworkersOID $DumpFileName $Nod +es $NO $StartOfOID $Unknown );
(:

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: Restricted assignment
by Anonymous Monk on Sep 28, 2004 at 10:29 UTC
    A spelling mistake ? you declare: my $Unkown = "Unkown"; # <--- Assignment 4 LINE 275 but you print: print $Unknown, "\n"; # <---- LINE 275!! use strict would catch that at compile time
      Thanx, that one helped at last

      sayonara
      ChFa

        Hint: If you use strict; Perl warns you about such typos.

        Jenda
        Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
           -- Rick Osborne

Re: Restricted assignment
by borisz (Canon) on Sep 28, 2004 at 09:10 UTC
    I guess it is exactly what the error message told you.
    perl -we 'print $x'
    We need a little more information. Perhaps a part of your code.
    Boris
Re: Restricted assignment
by borisz (Canon) on Sep 28, 2004 at 10:09 UTC
    From your updated node, I get the impression that $Unknown is out of scope. Inspect the lifetime of the my variable $Unknown careful.
    Boris
      Hi Boris, I'm now a bit puzzeled!

      Scope: what does it mean ?
      Lifetime: I assume to be restricted
      to the function or do{} section


      (:
      ChFa
        I mean, perhaps you leave the block with the var to early. But is look now like the spelling mistake that anon monk found.
        use warnings; { my $x = "xxx"; # $x get out of scope. } # print $x currently $::x witch is undefined currently print $x;
        Boris
Re: Restricted assignment
by fjaenale (Acolyte) on Sep 28, 2004 at 09:22 UTC
    Hello:

    Please check the print function. you may have other variables. Also Check the assigment, it may received no value at all.

    Also we need more information.

    Francisco Jaen
    www.cgi.com