Its in reference to my last question. I was looking at xlstand xpath, but I think I have the same problem I am having with xml simple. I dont know the path names in advance or how many nodes I have,a nd I need to take teh union of all nodes of all files in a directory before outputting. I was thinking that if I took the array of keys of the 1st subheadings in an xml file(in my example it would be the array of "required data, dm, worksheet data") and then turned each of those names into an array of the same name, I could loop over the keys array and use the new arrays as my placeholders for my union. basically, the program finds 3 headings a,b,c. It creates an array keys(a,b,c) and @a, @b,@c. Now I can say foreach(key){push(@a, keys($data->key)} remove the duplicates and I would have a more general version of my other program. Does this seem nuts to try? I know its a bit odd, but to me it seems liek it would work. Thanks for the continueed help. ~BJ


Paul Johnson wrote:

On Fri, Apr 15, 2005 at 03:22:56PM -0400, BJ wrote:



For instance if i had an array (a,b,c) can I through code create @a, @b, and @c? Just curious. ~BJ



Yes, you can, but you probably shouldn't. If you tell what you want to do I'm sure someone will tell you a better way to do it, and the answer will probably involve the word "hash".




#!/usr/bin/perl

# use module
use XML::Simple;
use Time::Local;

print "Welcome to the xml aggregator\n";
print "*****************************\n\n";
print "Enter the name of the directory to parse\n";
$dir=<STDIN>;
chomp $dir;
print "enter the name of the output file\n";
$ofile=<STDIN>;
chomp $ofile;
@rdkeys="";
@wskeys="";
@dmkeys="";
print "Beginning preprocessing\n";

# start preprocessor
($Second1) = localtime(time) ;
 opendir(C, $dir);
    my @ff = readdir(C);
    closedir(C);
    foreach my $file (@ff) {
        my $filename = $dir . '/' . $file;
        if ($file eq '.' || $file eq '..') {
        } else {


# create object $xml = new XML::Simple;

# read XML file
$data = $xml->XMLin("$filename");

# extract keys, remove duplicates
$rd=$data->{RequiredData};
$ws=$data->{WorksheetData};
$dm=$data->{DMan};
@keys=keys(%$rd);
push(@rdkeys,@keys);
%seen = ();
@rdkeys = grep { ! $seen{$_} ++ } @rdkeys;

@keys=keys(%$ws);
push(@wskeys,@keys);
%seen = ();
@wskeys = grep { ! $seen{$_} ++ } @wskeys;

@keys=keys(%$dm);
push(@dmkeys,@keys);
%seen = ();
@dmkeys = grep { ! $seen{$_} ++ } @dmkeys;}}
($Second2) = localtime(time) ;
$diff= ($Second2-$Second1);
$diff=$diff/60;
print "Beginning proccessing, estimated time $diff min\n";

#actual processing
open(OUT, ">$ofile");
$x=0;
@rdkeys=grep $_ ne "",@rdkeys;
foreach $item(@rdkeys){print OUT "$item|"};
@wskeys=grep $_ ne "",@wskeys;
foreach $item(@wskeys){print OUT "$item|"};
@dmkeys=grep $_ ne "",@dmkeys;
foreach $item(@dmkeys){print OUT "$item|"};
print OUT "\n";

# read XML file

foreach my $file (@ff) {
        my $filename = $dir . '/' . $file;
        if ($file eq '.' || $file eq '..') {
        } else {

$data = $xml->XMLin("$filename");

# extract keys, remove duplicates
$rd=$data->{RequiredData};
$ws=$data->{WorksheetData};
$dm=$data->{DMan};
@keys=keys(%$rd);
foreach $item(@rdkeys){
print OUT "$rd->{$item}|";}

@keys=keys(%$ws);
foreach $item(@wskeys){
print OUT "$ws->{$item}|";}

@keys=keys(%$dm);
foreach $item(@dmkeys){
print OUT "$dm->{$item}|";}

print OUT "\n";
}}
close OUT;
print "All operations completed. File Exported to $ofile\n";



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to