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:
Expand|Select|Wrap|Line Numbers
- 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;
- }
The problem is this code simply doesn't work. I don't know where to start looking.
Thanks