Professional Web Applications Themes

oriented object programming - PERL Miscellaneous

Greetings I have the following class: #!/usr/bin/perl package monPr; use HTML::Pr; ISA = qw(HTML::Pr); 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, ...

  1. #1

    Default oriented object programming

    Greetings

    I have the following class:

    #!/usr/bin/perl

    package monPr;
    use HTML::Pr;
    ISA = qw(HTML::Pr);


    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 monPr;
    my $p = monPr->new();
    $p->p_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
    franck Guest

  2. #2

    Default Re: oriented object programming

    [posted & mailed]

    On Mon, 21 Jul 2003, franck wrote:
    >package monPr;
    >use HTML::Pr;
    >ISA = qw(HTML::Pr);
    >
    >
    >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->p_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->p_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)

    Jeff 'japhy' Pinyan Guest

Similar Threads

  1. object oriented perl programming
    By sanjeeb in forum PERL Modules
    Replies: 1
    Last Post: April 20th, 07:19 PM
  2. 3D object oriented lingo
    By bgsBS in forum Macromedia Director 3D
    Replies: 1
    Last Post: July 25th, 11:46 AM
  3. Object Oriented Overkill ?
    By sonoflight in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 28th, 11:01 AM
  4. Object Oriented Web Design
    By Christian Cooper in forum ASP Components
    Replies: 2
    Last Post: May 9th, 08:14 AM
  5. packages object oriented
    By Eric Walker in forum PERL Beginners
    Replies: 10
    Last Post: September 13th, 09:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139