in reply to Interpolating Property strings help.
Please help.
I'm not sure I can help you solve your problem as it seems you've left out some of the code that produces the result. How does your $List variable get populated, for instance?
I can make some suggestions that might help you clean up your code regardless of whether they fix your problems.
Don't use prototypes unless you know what you are doing. By the way, you don't know what you are doing until you understand the points raised in Tom Christiansen's article.
Get rid of your isDefined() subroutine. All it is doing is allowing you to replace
withdefined $hash->{$key}
which is longer, less clear, and less efficient. Even if it made sense to use such a generic utility function (and in your case, it doesn't) it does not make sense to make it a method unless it does something specific to your class.$self->isDefined($hash, $key)
Consider using [^}]* in your regex as that's what you really seem to mean.
Consider making your regexen more robust in general. Your substitution:
will work on data that looks like foo = ${bar}/baz but it will fail on foo = ${ bar }/baz because it isn't tolerant of whitespace.$final =~ s/(\$\{$extractedVariable\}/$substituteWith/;
Rethink your style of naming variables. $extractedVariable might be a little confusing. Is that the variable name? Is that the value held by some variable somewhere? Etc. Something like $identifier is shorter, easier to read, and more descriptive. I also notice that after the line
you never bother to use the $substituteThis variable. You don't use it because you don't need to use it. Don't try to reassign variables to give them better names, just pick good names in the first place.my $substituteThis = $extractedVariable;
I have another suggestion that I didn't want to include in the above list because it is purely a matter of style and you may not even have a choice depending on coding guidelines in your environment. Consider naming your variables like $foo_bar rather than $fooBar. I strongly agree with those that claim it makes for much more readable code.
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Interpolating Property strings help.
by krisahoch (Deacon) on Jan 25, 2003 at 04:29 UTC | |
by Aristotle (Chancellor) on Jan 25, 2003 at 12:07 UTC |