LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2002, 05:12 AM   #1
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
OO in perl


is it me or the whole object orientated aspect of perl an utter utter cop out? just a package that hauls an additional reference around with it? bleurgh!
 
Old 09-24-2002, 08:37 AM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
(= In the dictionary next to the word "klunky", it has a picture of perl's OO stuff.

Don't get me wrong, I don't mind it.. I find perl's OO much more intuitive than C++'s... I ended up learning java to learn how OO should be done...

Once you get a package set up, the calls from the instantiation script are a breeze. It's the package setup that suxors.

Here's a demo of how I generally set up packages:

Code:
#!/usr/bin/perl
use strict;
use warnings;
 
##  filename: MyPackage.pm
package MyPackage;
 
my($name) = "MyPackage";
 
sub new {
  my($creator) = shift;
  my($class)   = ref($creator) || $creator;
 
  my($self)    = {
    dataPath   => "/path/to/stuff/",
    otherThing => "this or that",
  };
 
  return bless($self, $class);
}
 
sub someFunction($$)
{
  my($self) = shift;
  my($data) = shift ||
      die "$name: someFunction: Did not receive data\n";
 
  doSomethingWithData($data);
}
 
1;
And the invocant script:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use lib '/path/to/custom/packages/';
use MyPackage;
 
my($pkg) = new MyPackage();
 
$pkg->doSomething("Data to manip/use");
print "Data path is: $pkg->{dataPath}\n";
exit;
That's a bare-bones, anyway.. (=

Last edited by TheLinuxDuck; 09-24-2002 at 08:38 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM
can i set ~/public_html/perl as a perl directory for apache? doublefailure Linux - Networking 1 07-09-2002 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration