Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > oriented object programming

Reply
Thread Tools

oriented object programming

 
 
franck
Guest
Posts: n/a
 
      07-21-2003
Greetings

I have the following class:

#!/usr/bin/perl

package monParser;
use HTML:arser;
@ISA = qw(HTML:arser);


my $ligne;
my $flag = 0;
my %want = (tag => 'font',
attrs => { face => "Arial", size => "2" });

sub start_handler {
my($tag, $attr) = @_;
return unless $tag eq $want{tag};
foreach my $name ( keys %{$want{attrs}} ) {
return unless $attr->{$name} eq $want{attrs}{$name};
}; $flag = 1;
}

sub new
{
my ($class) = @_;
my $this = $class -> SUPER::new(api_version => 3,
start_h => [\&start_handler, "tagname, attr"],
end_h => [sub {$flag=0 if shift eq $want{tag}},
"tagname"],
text_h => [sub {$ligne.= shift, "\n" if $flag}, "dtext"],
);

$this -> {'LIGNE'} = $ligne;
bless ($this,$class);
return $this;
}

sub affiche
{
my ($this) = @_;
print $this->{'LIGNE'};
}
1;


I use this class in this script:

#!/usr/bin/perl -I /home/Perl/Programmes//module
use monParser;
my $p = monParser->new();
$p->parse_file("\/home\/Perl\/Programmes\/arrivee\/tempo\.txt") || die $!;
$p->affiche;

I would like to print the LIGNE attibut with the "affiche" method
It does not work !

What is the problem ?

Thanks.
Franck
 
Reply With Quote
 
 
 
 
Jeff 'japhy' Pinyan
Guest
Posts: n/a
 
      07-21-2003
[posted & mailed]

On Mon, 21 Jul 2003, franck wrote:

>package monParser;
>use HTML:arser;
>@ISA = qw(HTML:arser);
>
>
>my $ligne;


You defined $ligne here, but it doesn't have a value...

>my $flag = 0;
>my %want = (tag => 'font',
> attrs => { face => "Arial", size => "2" });
>
>sub start_handler {
> my($tag, $attr) = @_;
> return unless $tag eq $want{tag};
> foreach my $name ( keys %{$want{attrs}} ) {
> return unless $attr->{$name} eq $want{attrs}{$name};
> }; $flag = 1;
>}
>
>sub new
>{
> my ($class) = @_;
> my $this = $class -> SUPER::new(api_version => 3,
> start_h => [\&start_handler, "tagname, attr"],
> end_h => [sub {$flag=0 if shift eq $want{tag}},
>"tagname"],
> text_h => [sub {$ligne.= shift, "\n" if $flag}, "dtext"],
> );
>
> $this -> {'LIGNE'} = $ligne;


Here you've assigned $ligne to $this->{LIGNE}, but it still has no value.
Perhaps you wanted to get it from $_[1]?

> bless ($this,$class);
> return $this;
>}


>$p->parse_file("\/home\/Perl\/Programmes\/arrivee\/tempo\.txt") || die $!;


Is that argument supposed to be the value put in the LIGNE attribute? And
why are you backslashing everything?

$p->parse_file(/home/Perl/Programmes/arrivee/tempo.text") or die $!;

works just fine.

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

 
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
New C++ Book - C++ For Artists: The Art. Philosophy, And Science Of Object-Oriented Programming Rick Miller C++ 1 09-19-2013 02:55 AM
class-oriented rather than object-oriented? notnorwegian@yahoo.se Python 2 05-26-2008 04:42 PM
C (functional programming) VS C++ (object oriented programming) Joe Mayo C Programming 168 10-22-2007 01:00 AM
Object oriented does not mean class oriented rolo Ruby 3 04-09-2004 02:51 PM
About object oriented programming Martin C++ 5 09-11-2003 06:15 PM



Advertisments