Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > real, simple sample OOP intro text??!!

Reply
Thread Tools

real, simple sample OOP intro text??!!

 
 
Geoff Cox
Guest
Posts: n/a
 
      04-03-2004
Hello

I am trying to get started with Perl OOP but all the texts I have seen
so far, both from the Net and Perl bools are, either too abstract or
assume far too much ... I never want to see another OOP explanation
based on mythical cars, flowers, countries or whatever!

I am looking for a simple but real example of code based on a real
class (package) with the methods etc clearly explained.

Is this asking too much?!

Back in 1998, when I was trying to understand ODBC and CGI, I had the
same problem. In the end I was able to write a simple, step by step
approach (http://www.micro-active.com/dbase.htm) which was picked up
by a newsgroup and for several years afterwards I received thanks from
around the world for being in between too abstract and too complex ...

Can someone do the same for me now re Perl and OOP !!!???

Cheers

Geoff
 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      04-03-2004
Also sprach Geoff Cox:

> I am trying to get started with Perl OOP but all the texts I have seen
> so far, both from the Net and Perl bools are, either too abstract or
> assume far too much ... I never want to see another OOP explanation
> based on mythical cars, flowers, countries or whatever!


It appears to be rather popular among OOP-tutorial-writers to use these
kind of examples. I also sometimes wish they used simple real-world
scenarios. Or rather, I wished they had used them years ago when I
learnt it.

> I am looking for a simple but real example of code based on a real
> class (package) with the methods etc clearly explained.
>
> Is this asking too much?!


From your rant above, I conclude that you have probably already read
perlboot.pod. If not, then you'll hate it because it involves animals.

A little more demanding is perltoot.pod. It has the advantage that it
uses less colorful examples (and ones more likely to occur in the
context of computers and programming).

> Can someone do the same for me now re Perl and OOP !!!???


Do you consider yourself totally clueless as for OOP or have you already
picked up a few things from the tutorials that you've read rather
joylessly? Perhaps you have already reached stage 2 which means you know
little but you know enough to ask questions relating to OOP in this
group. People here will help you with them.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      04-04-2004
Geoff Cox wrote:

....


> I am trying to get started with Perl OOP but all the texts I have seen
> so far, both from the Net and Perl bools are, either too abstract or
> assume far too much ... I never want to see another OOP explanation
> based on mythical cars, flowers, countries or whatever!
>
> I am looking for a simple but real example of code based on a real
> class (package) with the methods etc clearly explained.


....


Have you tried "Object Oriented Perl" by Damian Conway, Manning
Publications? I thought it was crystal clear and generally excellent.
My apoligies if it is one of the offending books -- different things for
different folks.


> Geoff


--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      04-04-2004
On Sun, 04 Apr 2004 03:58:16 GMT, Bob Walton
<(E-Mail Removed)> wrote:

>Have you tried "Object Oriented Perl" by Damian Conway, Manning
>Publications? I thought it was crystal clear and generally excellent.
>My apoligies if it is one of the offending books -- different things for
>different folks.


Bob,

I am going to a book shop today to have a look at the all the latest
books on Perl and OOP so will include this one. Have seen an earlier
posting re Damian's book and the difficulty of sorting which is which
in the downloadable collection of scripts...have you seen this and do
you know if this has it been sorted out?

Cheers

Geoff



>
>
>> Geoff


 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-04-2004
>>>>> "GC" == Geoff Cox <(E-Mail Removed)> writes:

GC> I am going to a book shop today to have a look at the all the latest
GC> books on Perl and OOP so will include this one. Have seen an earlier
GC> posting re Damian's book and the difficulty of sorting which is which
GC> in the downloadable collection of scripts...have you seen this and do
GC> you know if this has it been sorted out?

AFAIK that wasn't a major issue. but i will second the book (and i
should know as i did a tech edit on it). it is the best (and only) book
on OOP and it is very well written. sure it uses a goofy set of examples
based on a cd collection but all books need to do that. real world
applications are usually too large for a single book to use and also
teach. but also most real world applications will not have the structure
that can be used to illustrate and compare different coding designs. you
choose a simple application so you can show how it can be developed in
many different ways and compare them. then the coding differences are
easily seen and can be highlighted. in a large real world app, only
small parts may have to do with an OO style or feature that is
important. so it would be very hard to show different ways of doing that
without reqwriting the whole thing.

this is just like learning math in school. 3 + 4 = 7 is needed to
compare to 4 + 3 = 7 and also 5 + 2 = 7. if you jumped right into
complex accounting examples, you would never grasp basic addition.

so you ain't gonna find any book or doc that does what you want. either
they use some dummy application to work with or they will focus on a
short program which highlights a particular feature.

so get OOP and read it and don't complain about something which will
never change as it is the right way to write a book on coding.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      04-04-2004

>joylessly? Perhaps you have already reached stage 2 which means you know
>little but you know enough to ask questions relating to OOP in this
>group. People here will help you with them.


Tassilo,

I was a little tired and frustrated when I posted above, but would
like to say that I was very grateful for the "mini tutorial" response
which you made to one of my earlier postings on this!

A couple of questions re that. I have used a modified version of your
code below and it does get me all the intro texts from the
total-260304.txt file but I have not understood how to get the <h2>
.... </h2> lines and I have not understood how to parse through the
html.htm file getting the <h2>.. </h2> data and the intro texts from
the total-260304.txt file in the order in which the <option statements
appear in html.htm.

I follow what you say re finding <option and value but cannot see how
I would get <h2>, <p> etc..

Would appreciate a little light here!

Geoff


package MyParser;
use base qw(HTML:arser);

open (OUT, ">>d:/a-keep9/nondb/parser/test/results.htm");
my $n=0;

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%'> \n");

sub start {
my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
if ($tagname eq 'option') {
&getintro($attr->{ value });
}
if ($tagname eq 'h') {
print OUT ("<tr><td>$attr->{ href } </td></tr> \n");
}
}

sub getintro {
open (INN, "d:/a-keep9/nondb/db/total-260304.txt");
while (defined (my $lineintro = <INN>)) {
if ($lineintro =~ /@_','(.*?)'\)\;/) {
print OUT ("<tr><td> $1 </td></tr>\n");

}

}
close(INN);
}

package main;
open (IN, "d:/a-keep9/nondb/parser/html.htm");
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse( $html );

print OUT ("</body></html \n");







>
>Tassilo


 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      04-04-2004
On Sun, 04 Apr 2004 07:28:20 GMT, Uri Guttman <(E-Mail Removed)>
wrote:

>so get OOP and read it and don't complain about something which will
>never change as it is the right way to write a book on coding.


Uri,

Are you really certain that OOP could not be taught from a real set of
data, a real class (module), real scripts etc? I will look at Damian's
book and try to be converted!

Cheers

Geoff




>uri


 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      04-04-2004
Also sprach Geoff Cox:

>>joylessly? Perhaps you have already reached stage 2 which means you know
>>little but you know enough to ask questions relating to OOP in this
>>group. People here will help you with them.

>
> Tassilo,
>
> I was a little tired and frustrated when I posted above, but would
> like to say that I was very grateful for the "mini tutorial" response
> which you made to one of my earlier postings on this!


It can be done for HTML:arser because it's just one module. I'd be a
bit more reluctant towards writing one on OOP. It's probably a topic too
huge for a single usenet posting.

Note that HTML:arser's subclassing technique doesn't require the full
set of OOP skills. It uses just one tiny aspect of it which I tried to
make clear in my posting. Apparently however 'subclass' can't be easily
explained without knowing what a 'class' in general is.

> A couple of questions re that. I have used a modified version of your
> code below and it does get me all the intro texts from the
> total-260304.txt file but I have not understood how to get the <h2>
> ... </h2> lines and I have not understood how to parse through the
> html.htm file getting the <h2>.. </h2> data and the intro texts from
> the total-260304.txt file in the order in which the <option statements
> appear in html.htm.
>
> I follow what you say re finding <option and value but cannot see how
> I would get <h2>, <p> etc..
>
> Would appreciate a little light here!
>
> Geoff
>


[ indenting fixed a bit ]

> package MyParser;
> use base qw(HTML:arser);
>
> open (OUT, ">>d:/a-keep9/nondb/parser/test/results.htm");
> my $n=0;
>
> print OUT ("<html><head><title>test</title></head><body> \n");
> print OUT ("<table width='100%'> \n");
>
> sub start {
> my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
> if ($tagname eq 'option') {
> &getintro($attr->{ value });
> }


For a tag like

<option value="bla">

this will call

getintro("bla");

in the moment when this tag was encountered in the HTML document.

> if ($tagname eq 'h') {
> print OUT ("<tr><td>$attr->{ href } </td></tr> \n");
> }


What is the <h> tag and why does it have an "href" attribute?
You said you were looking for <h2> tags. That would mean you'd at least
have to write:

if ($tagname eq 'h2') {

Also, <h1>-<h6> don't have an "href" attribute. The only attribute they
can have is AFAIK "align". Or are you trying to access the "href"
attribute of a previous tag? If you want to do that, you have to store
it for later use (usually on a stack or so) when the start() method is
called for the tag containing this attribute. By the time start() is
called for <h2>, %$attr wont have it because it belongs to a different
tag.

> }
>
> sub getintro {
> open (INN, "d:/a-keep9/nondb/db/total-260304.txt");
> while (defined (my $lineintro = <INN>)) {
> if ($lineintro =~ /@_','(.*?)'\)\;/) {
> print OUT ("<tr><td> $1 </td></tr>\n");
>
> }
>
> }
> close(INN);
> }


Now apparently you are searching for a line containing:

bla','<SOME_CHARACTERS>');

where you capture <SOME_CHARACTERS>.

Can you explain what kind of data there is in the file total-260304.txt?
To me it looks a bit like a fraction of the arguments for function calls.

At this point I don't understand how the <option>, <h2> and <p> tags
relate to each other. Can you give a small sample of the data in the
input HTML file and also of the data in the total-*.txt files?
And finally, show us how the result made from these files is supposed to
look like.

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      04-04-2004
>>>>> "GC" == Geoff Cox <(E-Mail Removed)> writes:

GC> On Sun, 04 Apr 2004 07:28:20 GMT, Uri Guttman <(E-Mail Removed)>
GC> wrote:

>> so get OOP and read it and don't complain about something which will
>> never change as it is the right way to write a book on coding.


GC> Are you really certain that OOP could not be taught from a real
GC> set of data, a real class (module), real scripts etc? I will look
GC> at Damian's book and try to be converted!

my point is true with almost any computer topic or book. true read world
things are way too complex for a single book. anything that can be
covered properely in a book needs to be simple. did you get my point
about making highlights and comparisons? a complex system would hide
them and make the book impossible to follow. there is this
time/space/complexity tradeoff when writing a book. if it falls outside
that boundary then few will read or buy it which makes it a
failure. simple examples make it accessible and the author can focus on
the coding ideas and not the actual data. i have read dozens of computer
books and none have ever done something with complex real world data.
the perl/mason book actually used a real world problem that was the
apprentice.perl.org site but even that isn't that complex.

and i reiterate, get and read OOP. you will learn plenty and it won't be
a waste of your money or time.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      04-04-2004
On 4 Apr 2004 08:52:54 GMT, "Tassilo v. Parseval"
<(E-Mail Removed)> wrote:

Tassilo,

>What is the <h> tag and why does it have an "href" attribute?
>You said you were looking for <h2> tags. That would mean you'd at least
>have to write:
>
> if ($tagname eq 'h2') {


href only because I did not know what to use ... nonsense!

>Can you explain what kind of data there is in the file total-260304.txt?
>To me it looks a bit like a fraction of the arguments for function calls.
>
>At this point I don't understand how the <option>, <h2> and <p> tags
>relate to each other. Can you give a small sample of the data in the
>input HTML file and also of the data in the total-*.txt files?
>And finally, show us how the result made from these files is supposed to
>look like.


My aim is to change a web site dependent on MySQL to a site which is
not. This is because the person who may take over the running of this
site would find MySQL etc too difficult...

So, there is a series of html files which have <h2> headings </h2>,
<p> text spread over several lines</p> and <options from which to
select a document. Once a particular document has been selected, the
summary text for the doc is obtained from the database, along with a
link to the zipped version of the full document for downloading.

So, I wish get the various headings, text, and summary texts from each
option in the order in whcih they appear in each html file and write
this info into a new html file.

Typical extract from html file

<h2 align="center">Business issues</h2>

<p align="center"><img src="images/image.jpg"</p>

<p>This section deals with jaklsdj kad klajksdl aksdk alksd jkla
asdkl ;aksd;lka;lskd ;lkal;sdk ;lkal;sdk; lal;sd</p>

<h2 align="center">Assignments</h2>

<p>asjd kjd asjdkh jaskdh jhasjdh ajsdhk jasd
djkadlkj lkajdkl akldj klasjd kljaksd kladjkla
akdl ;ak d;l ka;ldk l;a</p>

<form action="business.php" method="post" target="frameright">

<input type="hidden" name="sfield" value="name">
<input type="hidden" name="submit" value="1">/<b>Assignments</b><br>
<select name="term" size=2>
<option value="docs/adminops">Admin Operations</option>
<option value="docs/businesswork">Business at Work</option>
<option etc etc

I use the option value, which is the path to each doc, to search the
database for the document's summary text..

total-*.txt contains for example

INSERT INTO total VALUES ('docs/businesswork,'<h3>
gasdg asdhj ahjsd</h3>hajskdh ahjsd aksdj kash djk ahd sjkhajk
asdjk aj sdlkasd kals dkladj kjakldjk jakldjk aklsdjk lajsd
asldk aklsd;aksd ;ka;lsdkl a;lsdk.');

The result of all this will be html pages with various <h2> headings,
<p> text and summary texts for each document with links to the full
zipped document.

By the way I have just bought the O'Reilly Perl & LWP book. The Damian
Conway book costs 38.00! in London. It looks very good but perhaps
more than I need at the moment..


Cheers

Geoff



>
>Tassilo


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple OOP question Nemisis ASP .Net 10 08-25-2006 11:26 AM
looking for asp.net sample with vb.net backend sample is there one? Jake ASP .Net 0 02-09-2006 10:44 PM
Simple OOP, polymorphism design question Jacek Dziedzic C++ 6 09-04-2004 01:47 AM
Intro Chapter on OOP using Prothon David MacQuigg Python 0 04-10-2004 12:35 AM
simple definition of OOP? John Boorman C++ 1 02-02-2004 10:13 PM



Advertisments