in reply to Perl Modules
One thing I see quickly is that your pass your hash of tokens into loadAndParse, but that function does not pass them to any other function, nor does it set the $self->{tokens} attribute. Basically, the rest of your functions have nothing to work on. I don't think this will solve all the problems though.
Update:
Also, in your new function, I believe you have your %tokens call defined incorrectly. It looks like you want $self->{tokens} to be a hash containing the token as the key, and it's replacement as it's value. You would need something like:
This would define the token attribute of $self to be a hashref containing your mapping of token names to token values. However, rather than relying on %tokens being defined globally, I would recommend that you pass it into either your constructor, or propagate it through your parseData function.sub new { ... $self->{tokens} = \%tokens; ... }
Update II:
You could also do away with the $self->{tokens} part of your module all together. The tokens are only used in one place throughout your module---the parseData function. So you could change the code to:
and change the loadAndParse function to:sub parseData($) { my $self = shift; my ($data, %tokens) = @_; foreach my $match($data =~ /\%(\S+?)\%/g) { if($tokens{$match}) { $data =~ s/%$match%/$tokens{$match}/g; } else { $data =~ s/%$match%//g; } } $debug .= "parseData has been run<br>"; return($data); }
sub loadAndParse($%) { my $self = shift; my ($filename,%tokens) = @_; $data = loadFile($filename); $body = parseData($data, %tokens); $debug .= "parseData has been run<br>"; return($body); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Perl Modules
by duff (Parson) on Apr 23, 2004 at 21:06 UTC |