0

I have a following program but for some reason it is throwing an error and not parsing the xml file.

 my @findxmls;
 foreach my $searchxml(keys %xmlhash) {
 @findxmls= `find -name $findxml -maxdepth 4`;
 print Dumper (@findxmls);

up to this point works fine. it prints out all the xml files with the path.

 example of output
  y:\dir\subdir\procedure.xml
  y:\dir\otherdir\java.xml

but it does not work if i try to parse it

  foreach my $output (@findxmls) {                          
  my $parsexml = new XML::Simple;
      my $xmldata = $parser->XMLin($output );
  print Dumper ($xmldata);  
  } 

ERROR

File does not exist: y:/dir/subdir/procedure.xml at sample.pl line 20
1
  • You should supply at least one actual file name or a part of the real output. Commented Jun 25, 2012 at 18:35

1 Answer 1

2

Backticks include newlines (\n) in the output, so the contents of your @findxmls array all have newlines on them. Change your script to either

chomp( @findxmls= `find -name $findxml -maxdepth 4` );

or

foreach my $output (@findxmls) {   
    chomp( $output );
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

ehh, thanks. one more question would you recommend using chomp all the time ?
use chomp when you expect your input to have newlines -- say from backticks or reading from a filehandle -- and you want the input not to have newlines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.