use strict ; my(@list, $lineno, %hash) ; $lineno = 1 ; while( ) { next if /^\s*\#/ ; # line commented out next if /^\s*$/ ; # all whitespace print $_, " => " ; no strict ; # lets barewords be converted to strings @list = eval $_ ; use strict ; # back to strict error checking ## ## check for errors ## if( $@ ) { print STDERR "Error in config on line $lineno: $@\n" ; next ; } ## ## check to make sure we didn't more than we were expecting ## if( @list > 2 ) { print STDERR "Warning line $lineno produced more data than expected\n" ; } if( @list < 2 ) { print STDERR "Warning line $lineno didn't give a key, value\n" } print "@list[0,1]\n\n" ; if( exists $hash{$list[0]} ) { print STDERR "Warning line $lineno overwrites previous value\n" ; } $hash{$list[0]} = $list[1] ; } continue { $lineno++ ; # increment lineno each pass through the loop } __DATA__ # comment line entry0, value0 entryx, $ENV{HOME} entryy, "string with \"quote\" in it" entry1, "value 1a with local var \$lineno = $lineno" # comment ignored entry2, "value $ENV{HOME} with an env var" ## ## we can even evaluate expressions ## entry9, (3+3)*1.5 entry_trig, sin(3.14159/2) ## ## test the warnings ## bogus_entry, " ## ## line with than one result ## entry_warning, 4, 5 entry_waringx entry_dup, 0 entry_dup, 1