freelanceprogrammers.org Forum Index » Perl

Need guidelines


View user's profile Post To page top
sudhirspraikhar Posted: Tue Aug 02, 2005 8:58 am


Joined: 02 Aug 2005

Posts: 2
Need guidelines
Hi

Please check the following code.

I am the beginner in perl

Actually there are some files in one directory say with
extensions .txt and .doc

I need to list them in XML tags

As <opt>
<txt> somefile.txt </txt>
<doc> somefile.doc </doc>

</opt>

I have written this code for this but I am not able to get the o/p
as above :

#!/usr/bin/perl
use XML::Simple
$count = 0;


foreach $i (`find /home/blabla/ -name *.* `)
{
open(INFILE,"<$i");
open(OUTFILE,">>patternfile");
while($line = <INFILE>)
{
if($line= /txt/)
{
print OUTFILE $line;
$txt_xml{$txt} = $txt;
}
else
{
print "Line Is $line
";
print OUTFILE $line;

$doc_xml{$doc} = $doc;
}
}
print "Count Is $count
";
}
}
my $xsimple = XML::Simple->new();
print $xsimple->XMLout(\%doc_xml,noattr => 2, xmldecl => `<?xml
version="1.0">`);

close(INFILE);
close(OUTFILE);


this executes fine but the o/p will be as
<xml version 1.0>

<opt></opt>


But what I was expecting o/p as
<xml version 1.0>

<opt>

<txt> filename.txt</txt>

<doc> filename.doc</doc>
</opt>


Please guide me what do to get the desired o/p.


Regards

Sudhr
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help