1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use strict; use warnings; use XML::Twig; use File::Find; my $file ='\Users\ADMIN\Documents\probe'; my $FileResult = 'result.txt'; open( my $FhResult, '>', $FileResult )or die ("Unable to open file $FileResult\n$!"); find(\&wanted, $file); sub wanted { print $FhResult "Found it $File::Find::dir/$_\n" if /^[d or t]/i; }
Guest HenriCode (perl): (dl )print $FhResult "Found it $File::Find::dir/$_\n" if /^[d or t]/i;
perl code.pl *.xml
Guest HenriWie sieht denn dein Programm jetzt aus?C:\Users\ADMIN\Documents>perl new2.pl
Undefined subroutine &wanted::wanted called at C:/strawberry/perl/lib/File/Find.
pm line 691.
was bedeutet diesen Fehler, ich suche schon information darauf und finde leider nicht
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
#!/usr/bin/perl package wanted; use strict; use warnings; use XML::Twig; use Text::CSV; use File::Find; use wanted; &wanted(); &newwanted(); my $FileResult = $ARGV[1] || 'result.txt'; my $FhResult; my $folder ='.'; my $twig2= XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_value = $_->{'att'}->{'value'} // 'fault'; print $FhResult $attr_value . ","; }, }, ); File::Find::find({wanted => \&wanted}, 'C:\Users\ADMIN\Documents'); exit; sub newwanted { my ($dev,$ino,$mode,$nlink,$uid,$gid,$name); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && /^.*\.xml\z/s && processXML($name); } sub processXML ($) { print $FhResult( (split('_', "\n$_",2))[0] . ',' ); $twig2->parsefile($_); } open( $FhResult, '>', $FileResult ) or die("Unable to open file $FileResult\n$!"); find({ wanted => \&newwanted, }, $folder); close $FhResult;
Guest HenriHallo wie ich schon sagte ich kenne mich nicht gut aus
ich verstehe leider nict die Methode Wanted das ist der code leider bekomme ich immer eine Fehlermeldung.
Quote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use strict; use warnings; ## use XML::Twig; use File::Find; #my $file ='\Users\ADMIN\Documents\probe'; my $file = '/home/bananapi/progs'; my $FileResult = 'result.txt'; open( my $FhResult, '>', $FileResult )or die ("Unable to open file $FileResult\n$!"); find(\&wanted, $file); sub wanted { print $FhResult "Found it $File::Find::dir/$_\n" if /^[st]/i; }
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
use strict; use warnings; use XML::Twig; my @files = glob '*.xml'; my $file1 = shift @files; my $FileResult = 'result.txt'; open( my $FhResult, '>', $FileResult )or die ("Unable to open file $FileResult\n$!"); my $twig1= XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_name = $_->{'att'}->{'name'} // 'fault'; print $FhResult $attr_name . ","; }, }, ); print $FhResult( (split('_', $file1,2))[0] . ',' ); $twig1->parsefile($file1); for my $file (@files) { my $twig1 = XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_value = $_->{'att'}->{'value'} // 'fault'; print $FhResult $attr_value . ","; }, }, ); print $FhResult ( split( '_', "\n$file", 2 ) )[0] . ','; $twig1->parsefile($file1); } close $FhResult;
1 2 3 4 5 6 7
# vvvvv for my $file (@files) { ... # erstelle $twig1 $twig1->parsefile($file1); # ^^^^^^ }
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
use strict; use warnings; use XML::Twig; my $file1 = shift @ARGV; # erste Datei ist als erstes Argument angegeben my @files = glob '*.xml'; # lese alle xml-Dateien im Verzeichnis @files = grep { $_ ne $file1 } @files if defined $file1; # entferne $file1 aus Datei-Liste, wenn $file1 definiert ist my $FileResult = 'result.txt'; open( my $FhResult, '>', $FileResult )or die ("Unable to open file $FileResult\n$!"); my $twig1= XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_name = $_->{'att'}->{'name'} // 'fault'; print $FhResult $attr_name . ","; }, }, ); print $FhResult( (split('_', $file1,2))[0] . ',' ); $twig1->parsefile($file1); for my $file (@files) { my $twig1 = XML::Twig->new( twig_handlers => { 'Parameter' => sub { my $attr_value = $_->{'att'}->{'value'} // 'fault'; print $FhResult $attr_value . ","; }, }, ); print $FhResult ( split( '_', "\n$file", 2 ) )[0] . ','; $twig1->parsefile($file); # korrigiert; da hier wahrscheinlich die Dateien geparst werden sollen, die in @files stehen; da ist $file1 falsch! } close $FhResult;