in reply to Re: Can I do single-file, Object oriented perl?
in thread Can I do single-file, Object oriented perl?

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!

Replies are listed 'Best First'.
Re^3: Can I do single-file, Object oriented perl?
by BUU (Prior) on Jul 05, 2005 at 21:28 UTC
    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.
    Just to nitpick a tad, the shebang has nothing to do with the difference between a ".pl" and a ".pm". Perl sees no difference between files, whatever their extension happens to be. The only practical difference is that 'use' and 'require' will append a .pm to the package name you pass them. In any case, anything involving a shebang has to do with your shell/kernel.