Hello,
If you create a sub that takes its input from a global variable then you
get into 2 problems:
1. You cannot use recursion in your program since all recursed subs will
work on the same data which will be a pain to debug or verify
correctness.
2. Higher error probability since you have to remember what global
variables belong to which subs. It's much better to let the compiler do
that job, not you.
3. You cannot reuse any code because if I have a module that needs 100
global variables, and you have one that needs 50, then eventually we'll
come to a name collision.
4. It doesn't look good either. Consider:
printf "My name is %s and I'm %d years old\n", $name, $age;
should be rewritten to something like:
$printf_format = "My name is ....";
@printf_array = ($name, $age);
printf;
which is clearly ugly, unreadable, and error prone.
Hope this helps,,,
Aziz,,,
In article <005501c11849$88315c20$5ebcd43f@win>, "Dexter Coelho"
<[EMAIL PROTECTED]> wrote:
> With regards to local variables in subs.
>
> Can I create a local var in a sub without passing arguments to it.
>
> I guess you can say local var=global var; so this is no reason to
> pass arguments.
>
>
> By the way, I see using local vars in subs to prevent changing a value
> of a global var if your
> the new varaible name is the same as the global. I tend to create new
> variable names so to me
> this local stuff is really a matter of convenience. You agree.
>
> Dexter
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]