On Sun, 15 May 2005 00:20:54 -0400 Jason Dixon <[EMAIL PROTECTED]> wrote:
> What about declaring a variable in the block it's being used is so > difficult for you? It's pretty simple... define a variable in the > main namespace, it's a global. Define it in a block, it's lexical. Uh, that's not how perl works, that's how most languages work. With perl, if you define a variable in a block, its still package global. Variables are only lexical scope if they are declared with "my". Hence my complaining that you have to explicitly declare variables as local, when it should be assumed unless stated otherwise, like with most languages. > I don't quite gather why you think declaring args to a sub is any > more advantageous than passing args via @_. And yes, this can be a > benefit when you might not need to pass all the args at any one time. First of all, that's not a benefit. In most languages you can have optional arguments to functions, without forcing all functions to take only a single array of scalar variables. Declaring args makes it quick and easy to see what arguments a function takes, even if you are a script and not a person. It also lets you require certain args, set defaults for args, and pass non scalar args, without wasting extra time doing that work yourself. With perl you can only pass an array as a reference, if you want a second array you have to copy the one passed as a reference manually in the sub. And of course, if all you want is an array of args, languages that let you declare arguments to functions can give you that just fine. Perl is all about being flexible and saving programmer time, yet something basic like functions is implimented in an inflexible way that requires programmers to spend extra time checking args. Declaring args is both more flexible, and a time saver. Adam