A few points here. First off, most of us are case sensitive. In fact, Perl usually is case sensitive. As in, book.pm is not the same thing as Book.pm. Normally, this only matters in non-OO modules where you're importing stuff (e.g., "use Foo qw(bar baz)"), but, still, it's confusing. Since all-lowercase modules are, by convention, reserved for pragmas, I'd suggest sticking to Book instead of book.

Second, generally it's preferred if you post a minimal "working" example. By "working" I do not mean "code works flawlessly" but "code shows the entire logic that exhibits the problem."

Because of this, I'm having a hard time groking your "try to toss the file" snippet, what context, etc., where $html, $header, and $time are coming from, that sort of thing. Your code very well could work perfectly, but it's hard to tell without more context.

Ok, after reading closer, I see the issue. When you call an object method, the first value passed in is always the object itself. What you need to do is extract it. Most people call this "$self" though those from a C++ background call it "$this".

sub header { my $self = shift; # add this line here. my $html = shift; my $header = shift; my $time = shift;
After that, you can access your object through $self, and everything will be in the right variables.


In reply to Re: Passing variable to method in perl by Tanktalus
in thread Passing variable to method in perl by bubnoff

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.