473,883 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[perl-python] 20050124 classes & objects

© # -*- coding: utf-8 -*-
© # Python
© # in Python, one can define a boxed set
© # of data and functions, which are
© # traditionally known as "class".
© # in the following, we define a set of data
© # and functions as a class, and name it xxx
© class xxx:
© "a class extempore! (^_^)"
© i=1 # i'm a piece of data
© def okaydokey(self) : return "okaydokey"
© def square(self,a): return a**a
© # in the following,
© # we create an object, of the class xxx.
© # also known as "instantiat e a class".
© x = xxx()
© # data or functions defined in a class
© # are called the class's attributes or
© # methods.
© # to use them, append a dot and
© # their name after the object's name.
© print 'value of attribute i is:', x.i
© print "3 squared is:", x.square(3)
© print "okaydokey called:", x.okaydokey()
© # in the definition of function inside a
© # class, the first parameter "self" is
© # necessary. (you'll know why when you need to)
© # the first line in the class definition
© # is the class's documentation. It can
© # be accessed thru the __doc__
© # attribute.
© print "xxx's doc string is:", x.__doc__
© # one can change data inside the class
© x.i = 400
© # one can also add new data to the class
© x.j=4
© print x.j
© # or even override a method
© x.square = 333
© # (the following line will no longer work)
© # print "3 squared is:", x.square(3)
© # in Python, one must be careful not to
© # overwrite data or methods defined in a
© # class.


for a obfuscated treatment with a few
extra info, see

in Python terminal, type help() then
topic CLASSES to read about existing
datatypes as classes, and classes in

try to write a class with one data of
integer and two functions, one
increases it by 1, one decreases it by
1. note: inside a class definition,
to refer to data inside itself use
self. e.g. self.i

Perl does not support classes or
objects in the so-called "Object
Oriented" programing. However, a
complete set of emulations of OO
style of programing have been done,
resulting in modules and books and
many documentations and tutorials.

here is a quote from
perldoc perlobj

First you need to understand what
references are in Perl. See perlref for
that. Second, if you still find the
following reference work too
complicated, a tutorial on
object-oriented programming in Perl can
be found in perltoot and perltooc.

it goes on and sayz:

If you're still with us, then here are
three very simple definitions that you
should find reassuring.

1. An object is simply a reference
that happens to know which class
it belongs to.

2. A class is simply a package that
happens to provide methods to deal
with object references.

3. A method is simply a subroutine
that expects an object reference
(or a package name, for class
methods) as the first argument.

Good luck.
Note: this post is from the Perl-Python a-day mailing list at
to subscribe, send an email to perl-python-subscribe @ yahoogroups.com
if you are reading it on a web page, program examples may not run
because html conversion often breaks the code.

Jul 18 '05 #1
2 1694
Xah Lee wrote:
Perl does not support classes or
objects in the so-called "Object
Oriented" programing.
Boy, the ignorance never stops, does it?
However, a
complete set of emulations of OO
style of programing have been done,
resulting in modules and books and
many documentations and tutorials.

It doesn't have OO, but it emulates in software!
Better go with python, which has hardware OO. :-)
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
Jul 18 '05 #2
Chris Mattern wrote:

It doesn't have OO, but it emulates in software!
Better go with python, which has hardware OO. :-)

Chris don't feed the troll
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question is this... is Perl so much better at parsing text files and outputing that we would see a substantial speed increase? We process about 10 million records in flat files a day for reformatting before putting them in a DB. Also, when it comes to...
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually have two interpreters at the same time. On Red Hat Linux 7.3 with Perl 5.6.1, the attached program segfaults. On Red Hat 9 with Perl 5.8.0, it works perfectly. Save the program code as "test-embed-perl.c" and the build script as "buildte". ...
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you might want to skip to the bottom, where I try "make" and the fatal errors start happening.
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt fails in a rather dramatic way, spewing out thousands of "relocation remains"... I'm somewhat lost on what to do next, the documentation that came along with the Perl package is somewhat sparse. Anyone have suggestions? % uname -a
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the functionality of php. The extension uses the '$perl->eval' function. i am kind of stuck with the syntax or how to put the php variable into the perl script. I have a form where the user puts in a grid reference. Then a php script that gets the...
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.