ERLEDIGT
NEIN
NEIN
ANTWORTEN
3
3
ZUGRIFFE
460
460
EMPFEHLEN
-
hallo
wie mach ich aus dem code ->
(kommt aus einem Buch) ein Modul?Code :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
use XML::Parser; # initialize the parser my $parser = XML::Parser->new( Handlers => { Start=>\&handle_start, End=>\&handle_end, }); $parser->parsefile( shift @ARGV ); my @element_stack; # remember which elements are open # process a start-of-element event: print message about element # sub handle_start { my( $expat, $element, %attrs ) = @_; # ask the expat object about our position my $line = $expat->current_line; print "I see an $element element starting on line $line!\n"; # remember this element and its starting position by pushing a # little hash onto the element stack push( @element_stack, { element=>$element, line=>$line }); if( %attrs ) { print "It has these attributes:\n"; while( my( $key, $value ) = each( %attrs )) { print "\t$key => $value\n"; } } } # process an end-of-element event # sub handle_end { my( $expat, $element ) = @_; # We'll just pop from the element stack with blind faith that # we'll get the correct closing element, unlike what our # homebrewed well-formedness did, since XML::Parser will scream # bloody murder if any well-formedness errors creep in. my $element_record = pop( @element_stack ); print "I see that $element element that started on line ", $$element_record{ line }, " is closing now.\n"; }
ich glaub das Problem liegt irgendwie hier ->
wenn ich über das eine Funktion mache und versuche die Funktion aufzurufen dann krieg ich Fehler - ich glaube sub hande_start und sub handle_end werden darum nicht mehr aufgerufen - das was ich aber will ist eine Funktion machen die ich dann von einem Perl file aufrufen kann und den ganzen parse Prozess starten!Code :1 2 3 4 5 6
my $parser = XML::Parser->new( Handlers => { Start=>\&handle_start, End=>\&handle_end, }); $parser->parsefile( shift @ARGV );
thx
-
Code :
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
package Downset04Test; use XML::Parser; # initialize the parser my $parser = XML::Parser->new( Handlers => { Start=>\&handle_start, End=>\&handle_end, }); my @element_stack; # remember which elements are open sub parse_file{ my ($file) = @_; $parser->parsefile($file); } # process a start-of-element event: print message about element # sub handle_start { my( $expat, $element, %attrs ) = @_; # ask the expat object about our position my $line = $expat->current_line; print "I see an $element element starting on line $line!\n"; # remember this element and its starting position by pushing a # little hash onto the element stack push( @element_stack, { element=>$element, line=>$line }); if( %attrs ) { print "It has these attributes:\n"; while( my( $key, $value ) = each( %attrs )) { print "\t$key => $value\n"; } } } # process an end-of-element event # sub handle_end { my( $expat, $element ) = @_; # We'll just pop from the element stack with blind faith that # we'll get the correct closing element, unlike what our # homebrewed well-formedness did, since XML::Parser will scream # bloody murder if any well-formedness errors creep in. my $element_record = pop( @element_stack ); print "I see that $element element that started on line ", $$element_record{ line }, " is closing now.\n"; } 1;
Dann im Skript:Code :1 2 3 4 5 6 7 8
#!/usr/bin/perl use strict; use warnings; use Downset04Test; my $file = '/path/to/file.xml'; Downset04Test::parse_file($file);
Zum Thema Module schreiben: http://wiki.perl-community.de/bin/vi...lleIchEinModul
http://de.selfhtml.org/perl/module/intro.htm
-
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use XML::Parser; # initialize the parser my $parser = XML::Parser->new( Handlers => { Start=>\&handle_start, End=>\&handle_end, }); my @element_stack; # remember which elements are open my ($file) = @_; $parser->parsefile($file); } 1;
eine andere version da bin ich mit probieren draufgekommen es muss einfach der 1; am ende der funktion sein! ist das gut? oder 1; immer nur am ende des files?
-
Das Modul muss einen "wahren" Wert zurückliefern. Der Übersichtlichkeit wegen schreibt man das 1; normalerweise ans Ende des Moduls...
Ähnliche Themen
-
Problem mit SSH2 modul
Von J0hn B0y im Forum Hosting & WebserverAntworten: 0Letzter Beitrag: 25.11.10, 12:31 -
gallery / modul problem....
Von digifoho im Forum PHPAntworten: 7Letzter Beitrag: 10.07.06, 18:37 -
[C] Problem bei einem Eggdrop Modul - Function nach x Sekunden
Von Gargoyle im Forum C/C++Antworten: 9Letzter Beitrag: 26.07.05, 13:37 -
Problem mit Perl Modul in CGI Script
Von blackbirdthefirst im Forum CGI, Perl, Python, Ruby, Power ShellAntworten: 1Letzter Beitrag: 26.11.04, 12:26 -
Problem mit mod_auth_mysql Modul
Von DJ_Apfel im Forum Hosting & WebserverAntworten: 0Letzter Beitrag: 07.06.04, 13:05





Zitieren
Login





