-----Original Message-----
From: Dexter Coelho <[EMAIL PROTECTED]>
To: Albena Georgieva <[EMAIL PROTECTED]>; [EMAIL PROTECTED]
<[EMAIL PROTECTED]>
Date: Sunday, July 29, 2001 12:21 PM
Subject: Re: Question about subs and functions
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
>
>
>
>
>-----Original Message-----
>From: Albena Georgieva <[EMAIL PROTECTED]>
>To: Dexter Coelho <[EMAIL PROTECTED]>; [EMAIL PROTECTED]
><[EMAIL PROTECTED]>
>Date: Sunday, July 29, 2001 11:24 AM
>Subject: Re: Question about subs and functions
>
>
>>> What should cause me to have to pass variables to a subroutine through
>>> arguments?
>>
>>One of the answers could be reusability and modularity. If you use
>>arguments, you can call this subroutine whenever you like and from
>different
>>programs too and not be dependent on the main program to define global
>vars.
>>
>>
>>imagine, I need to open 100 files. So, I write a subroutine for openning a
>>file:
>>
>>sub open_file {
>>$file_name = $_[0];
>>
>>...
>>}
>>
>>
>>then I use one subroutine for openning 100 files, by prviding the file
name
>>as an argument.
>>
>>In your practise, I would have to write 100 subroutines, each of then
>>referencing different global variable with the name of the file to be
>>opened.
>>
>>sub open_file1 {
>>$file_name = $my_global_var1;
>>
>>...
>>}
>>
>>sub open_file2 {
>>$file_name = $my_global_var2;
>>
>>...
>>}
>>
>>Hope it helps,
>>Albena
>>
>>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]