Hello,
I would like to scan a certain directory for XML files. Then I want to take in every XML file, read it, and stores the contents as a string in an array. For example, if the directory has file1.xml, file2.xml, and file3.xml, they would all be scanned and read. Then, all the contents of file1.xml would be stored in an array as the first element:
@array[0] would contain the stuff in file1.xml
@array[1] would contain the stuff in file2.xml
etc.
This is what I have:
readTextFile is another sub that has been tested. No problems there. addSlash adds a slash at the end of the directory so that the files can be opened. This is also tried and tested.
The problem is this code simply doesn't work. I don't know where to start looking.
Thanks
I would like to scan a certain directory for XML files. Then I want to take in every XML file, read it, and stores the contents as a string in an array. For example, if the directory has file1.xml, file2.xml, and file3.xml, they would all be scanned and read. Then, all the contents of file1.xml would be stored in an array as the first element:
@array[0] would contain the stuff in file1.xml
@array[1] would contain the stuff in file2.xml
etc.
This is what I have:
Code:
sub getComponents
{
my $dir = shift;
my @Components = ();
my @xmlFiles = ();
if ( -d $dir )
{
open ( COMPONENTS, $dir );
@xmlFiles = grep ( /^(.+)\.xml$/, grep ( !/^.{1,2}$/, readdir( COMPONENTS ) ) );
closedir ( COMPONENTS );
$dir = addSlash( $dir );
foreach ( @xmlFiles )
{
my @fileInfo = readTextFile ( $dir . $_ );
push( @Components, \@fileInfo );
}
}
return @Components;
}
readTextFile is another sub that has been tested. No problems there. addSlash adds a slash at the end of the directory so that the files can be opened. This is also tried and tested.
The problem is this code simply doesn't work. I don't know where to start looking.
Thanks