1
2
3
soundSet = { name = "bus_modern", horn = "vehicle/truck_modern/horn.wav" }
id = "vehicle/bus/citaro/lod_0_w2.msh",
"vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w2.msh", "vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w3.msh",
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
open $filehandle, "<", $file or die "can't open $file\n"; while (<$filehandle>) { my $line=$_; my $count=0; $count++ while ($line =~ m/\//g); # looks like we found a file-reference if ( $count > 1) { # remove all whitespace now # prefix whitespace $line =~ s/^\s+//; # suffix whitespace $line =~ ~ s/\s+$//; # intermediate whitespace $line=~ s/ //g; # remove everything until first occurance of " $line=~ s/[^\"]*\"//; # chop off all chars after " my $oper = index($line, '"'); my $word = substr($line, 0, $oper); $line=$word; # putting it together # buildpath returns a complete path & filename depending on wich prefix is # used for the current file my $searchfile=buildpath($line); if ( -e $searchfile ) { pdebug(1,"found\n"); } else { pdebug(1,"not found\n"); print "\nunmatched reference in file:\n$file\n"; # findline prints the Linenumber of a string in a file findline($file,$line); print"\ncouldn't find file:\n $searchfile\nreferenced as:\n$line\n"; } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl use strict; use warnings; while ( my $line = <DATA> ) { my @candidates = $line =~ m{ "([^"]+)" }xmsg; my @paths = grep{ m{/} }@candidates; print sprintf "found on line %s: %s\n", $., join ', ', @paths; } __DATA__ soundSet = { name = "bus_modern", horn = "vehicle/truck_modern/horn.wav" } id = "vehicle/bus/citaro/lod_0_w2.msh", "vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w2.msh", "vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w3.msh",
1
2
3
4
$ perl paths.pl
found on line 1: vehicle/truck_modern/horn.wav
found on line 2: vehicle/bus/citaro/lod_0_w2.msh
found on line 3: vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w2.msh, vehicle/bus/berkhof_duvedec/berkhof_duvedec_lod_0_w3.msh
Guest errorsmithIch muss also die Dateipfade irgendwie aus den Strings extrahieren. Mein Ansatz sieht bisher so aus, das ich alle Whitespace-Zeichen entferne und dann mittels regex die Zeichen zwischen den "" extrahiert habe. Das funktioniert allerdings im 3. Beispiel nicht, da dort zwei Dateien referenziert sind.
$line =~ m{ "([^"]+)" }xmsg;
Guest errorsmith@hlubenow:
Dafür benötige ich aber irgendwas woran ich es festmachen kann an welchen Stellen er ansetzen soll. Meine Strings sind dafür (glaube ich) zu verschieden.