in reply to lexical scope in if/elsif tests

The mys are outside of the squiggly brackets of the if.

That means they look like they're in the outer scope to me ;)

Replies are listed 'Best First'.
Re^2: lexical scope in if/elsif tests
by CountZero (Bishop) on Apr 05, 2010 at 13:46 UTC
    Not so: the $key and $val lexical variables are scoped to the whole of the if ... elsif ... else ... block. You get an error if you use them outside of that block.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Good to know; I'll have to shift my perspective a little bit to make it look right.