perl - "Uninitialized value" false positive -
i think perl (5.8.8 on centos kernel 2.6.18-308.8.1.el5) giving me false positive 'uninitialized variable' warning. of searching turns legitimate uninitialized value problems. perhaps mine too, , if that's case explanation of what's going on (and how correctly i'm trying do) awesome. i've looked @ many references hex() , correct function argument idioms, , think i'm doing of correctly.
my script reads 2 text files: 1 contains 32bit hardware address , other contains 32bit data read address. values in each file 8 hex digits long , both files 100% matched (line 1 in address file corresponds line 1 in data file). when data value non-zero fine, when data value 0 warning:
use of uninitialized value in string eq @ ../vmetro_parser.pl line 248. use of uninitialized value in hex @ ../vmetro_parser.pl line 250. relevant code:
sub ppreg_tx_mode_reg { my( $data ) = @_; # first arg should data field $ret = "\t"; if( $data eq "00000000" ) { print "tx_mode_reg got 0 input\n"; } #line 248 #croak( "data not defined!" ) unless defined $data; my( $hex ) = hex($data); #line 250 $ret .= sprintf( "clear ints: %02x ", (($hex >> 25) & 0x7f) ); input produces expected behavior:
address: 90000004 data: 00000004 output of perl script:
90000004 00000004 -> wr tx00 mode_reg clear ints: 00 input produces unexpected 'uninitialized value' warning:
address: 90000004 data: 00000000 output of perl script:
90000004 00000000 -> wr tx00 mode_reg tx_mode_reg got 0 input clear ints: 00 clearly, recognizing argument passed in string "00000000" , yet thinks undef (the croak line fires if uncomment it). gives?
one interesting thing there other instances of data being 0 no warnings thrown. other 0 data processed different function, , occurs after line throws warning, processing identical (except obvious debug actions in code above, added because of warning).
e.g.
sub ppreg_rx_master_mode_reg { my( $data ) = @_; # first arg should data field $ret = "\t"; my( $hex ) = hex($data); does not throw warnings.
this unlikely problem perl.
remember warnings sent stderr whereas output going stdout. 2 aren't in sync, can't tie warning output same record.
it may use print , die instead of croak warnings displayed in correct sequence.
i suggest change subroutine
sub ppreg_tx_mode_reg { ($data) = @_; { warn 'undefined $data parameter'; return; } unless defined $data; . . . } so code isn't executed invalid data.
your problem in code extracts data file records. handling blank lines correctly? please show part of code if want it.
Comments
Post a Comment