OK, so I am a PHP programmer, and I am just now learning Perl. I am trying to create my first module, yet I am having some trouble. I'm still trying to get a grasp on OOP in Perl. The following is the basis of my module:
package HTML::pageParser; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT); use Exporter; @ISA = qw(Exporter); # Make some utility functions available if asked for @EXPORT = (&loadAndParse &loadFile &parseData $result $debug); # this creates our class/object sub new { my $proto = shift; my $class = ref($proto) || $proto; my ($sysLoc) = my @orig_args = @_; my $self = {}; $self->{%tokens} = []; $self->{sysLoc} = $sysLoc; bless ($self, $class); $debug .= "new class has been run<br>"; return $self; } # this file reads a text file and loads the contents into an array sub loadFile($) { my $self = shift; my ($filename) = @_; if(open this, $filename) { while ($line = <this>) { $body .= $line; } close this; } else die("cannot open the file:" $filename); $debug .= "loadFile has been run<br>"; return($body); } # this function parses through the contents of a scalar variable and d +oes a search/replace on the tokens # the only thing left to figure out in this function is to eliminate t +he duplicate matches found # before doing the replacing of any tokens. This will be a minor decre +ase in processor resources. sub parseData($) { my $self = shift; my ($data) = @_; my %tokens = $self->{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); } # this is a quick way to both load a flat file and parse it's contents + for tokens. sub loadAndParse($%) { my $self = shift; my ($filename,%tokens) = @_; $data = loadFile($filename); $body = parseData($data); $debug .= "parseData has been run<br>"; return($body); } 1; # so the require or use succeeds
Here's the test code i wrote that 'use's the module.
# this is just a test file to see if my new module is functioning prop +erly use HTML::pageParser; #we need to make sure that we enter the path to our active directory h +ere $sysLoc = "E:\\test\\"; print "Content-Type: text/html\n\n"; # here are just some test tokens to make sure that this works $myPage = pageParser->new($sysLoc); $tokens{fName} = "Brandon"; $tokens{lName} = "Smith"; $data = $myPage->loadAndParse("parseThis.txt",%tokens); print $result;
When the test code is executed, it returns absolutely nothing... I am assuming that I am missing some really basic concept. But I have been pulling out my hair trying to figure it out, and am now turning to the wise ones for assistance. ANY fixes, suggestions or remarks are quite welcome. Thanks.

In reply to Perl Modules by eNtropicChild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.