[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Objekt orienteret perl problemer



Allan Nielsen wrote:
Hej

Jeg sider og rode med lidt objekt orienteret programmering i perl, jeg
vil gerne lave en klasse som jeg kan bruge til at læse/skrive værdier i
en givet xmlfil.
Jeg har lavet 2 filer, en metaFile.pm og en test.pl.

metaFile.pm:

#!/usr/bin/perl
package metaFile;
$VERISON = 0.01;
use XML::Parser;
use strict;

sub new{
  my $class = shift;
  my $self = {};
  bless $self;
  $self->{'xmlfile'} = $_[0];
  print "XMLFile: ".$self->{xmlfile}."\n";
  # initialize parser and read the file
  $self->{'parser'} = new XML::Parser( Style => 'Tree' );
  print "Parser: ".$self->{parser}."\n";
  $self->{'tree'}   = $self->{parser}->parsefile( $self->{xmlfile} );
Skulle dette have været
  $self->{'tree'}   = $self->{'parser'}->parsefile( $self->{xmlfile} );
  return $self;
}

test.pl:

#!/usr/bin/perl

use metaFile;
use strict;

my $obj2 = metaFile->new("../testFiles/.b.metaxml");

Når jeg forsøger at kører test.pl får jeg følgende output:

XMLFile: /home/allan/Projects/perl/xmlfs/testFiles/.b.metaxml
Parser: REF(0x8232b20)
Can't call method "parsefile" on unblessed reference at metaFile.pm line
17.

Hvis jeg laver det "ikke" objekt orienteret virker det fint, nogle bud
på hvad der er galt.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *