-
I've never had any need to use reset, untill this post I didn't even know what it did. Having now read the docs, I can't imagine why anyone would want to use this in a world that includes "my".
-
The issue with global variables is that if you packaged this and I tried to use/require it in a script that allready has a variable named "$FILE" your code would destroy my variable. Try this...
#!/usr/bin/perl
$FILE = "this is my file, i'm going to want this value later\n";
print $FILE;
require('./varstruct.pl');
print $FILE;
&VARSTRUCTOR('show', 'E: subs(VARSTRUCTOR)', './varstruct.pl'); # Test
print $FILE;
-
Your whole strategry for finding variables is massively flawed. I mean, what is this all about?? ...
#
# # Extract scalars and arrays. If not an array used in push, require
+an equals sign.
# while (($FILE =~ s/([^\\]|[^\\]\\\\)([\@\$][^\d\W]\w*(\[.*?\])?)\s*=
+//)||
# ($FILE =~ s/push[^\w_]*([^\\]|[^\\]\\\\)(\@[^\d\W]\w*)//))
#
...if the code I want to analyze has an array that's not initalized with "=" or used in a "push" call, then your function doesn't find it? That hardly sounds like "Perl's reset function, with extra features"
...there's a lot of other little things about this code that scare me, but i'm too tired to keep iterating over them. the more i look at it, the more depressed i get.
| [reply] [d/l] [select] |
... the fact remains that not all variables in some good scripts are "my" variables, and sometimes those all need to be reset. I believe I have such a script...
I believe the sense of the monastery is that there are better ways to address the need to "reset" variables.
If you would post your script (in a new thread), I'm sure people would fall over themselves to come up with other ways of tackling this issue.
The reason this has kicked up such a furor is that other monks are trying to communicate a lesson to you that they have learned through personal experience: that adjusting one's approach so that it takes advantage of mainstream features (my, local, references and the like) leads to more reliable solutions than if they relied on a piece of Perl code to parse other Perl code.
If your other script really demonstrates the need for the variable-clearing technique you've posted, you could force those monks to eat their words. On the other hand, if the monks show you a simpler way to avoid this whole problem, you will have both learned something new and saved yourself from the significant effort involved in making your Perl parser more sophisticated. | [reply] |