Chuck,
Thanks for your help but I probably did not make it clear that I chose to use the same name since I am appending to the same file.
Why I am having to open it many times, because I am calling different modules within the Perl program and before I call the module I close the file and after the module has been called I reopen the module.
Any ideas??
Thanks,
Jonathan
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 02, 2001 5:50 PM
To: '[EMAIL PROTECTED]'
Subject: Re: masks earlier declaration in same scope
>Hello,
>I have a parameter
>my $name0 = "c:/test";
>$name0 is used for opening a file throughout my program.
>I have used it more than once and therefore it says that $name0 masks
earlier declaration in same scope.
>I have tried to undef $name0 but it still get this error.
>The program will run but I would like to remove this error altogether.
>What would you recommend I do in this case.
>Many thanks,
>Jonathan
Jonathon,
you answered your own question... you use it more than once - don't.
If you know what file names you are going to be working with in advance,
setup a variable for each one at the start of your program.
my $file1 = "C:/test";
my $file2 = "C:/test2";
then use them to open files when and where they are needed BY name. Using
just one variable name for different files can be confusing for someone
else trying to figure out what your code does. If they see you assign it
at the top, but then page down to the very end of your file and see it used
to open a file, they will assume it is the same file it was assigned to at
the top, when in reality you may have reassigned it 10 times in the body of
your program.
IMHO it is poor form to use one variable to represent every file your
program opens and works with. It saves an insignificant amount of memory
(if any) over using properly named variables for each file needed.
Chuck
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users