That's very wrong. You should only bless references. This piece of code here is bound to fail.

Apologies. Of course my production code does something like this:

my $self = { user_name => 'fubar', num_days => 0, }; bless ($self, $class);

I threw the tom/dick/harry example together from memory. I wanted to emphasize that I was defining 3 classes in the same file - something that other OO languages do not like.

If it works in the .pm, it'll work in the .pl. Another error must have been introduced.

Ikegami - I think you got it - but with one exception:

You have to include shebang (#!/usr/bin/perl) at the top of a .pl, but not at the top of a .pm file.

I took my working .pm file and tried to get it to work as a .pl and it threw errors. But I did not notice the error messages were BASH error messages instead of Perl messages. (duh)

I put shebang at the top of the script - and now it actually works. Thanks Monks!


In reply to Re^2: Can I do single-file, Object oriented perl? by FatDog
in thread Can I do single-file, Object oriented perl? by FatDog

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.