Re: Perl script does not work




"CSUIDL PROGRAMMEr" <syedamjad_a@xxxxxxxxx> wrote in message
news:1146333247.131872.286590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Folk
I am trying hard to run this script on fedora 3

It changes the following pattern in xml files

<!CDATA[slaaam]]> TO

<slaaam>

But it does not work. Any reasons



How does it not work? What you want it to do is half the equation. What it's
actually doing is also required for people to have any way of helping you.



The script is a as follows

#!/usr/bin/perl
use strict;
use warnings;
my $start_dir = "/home/amjad/chatTrackBot_v1.5/xml_logs";
chdir($start_dir) or die "Can't chdir $start_dir: $!";
my @files = <*.xml>;
my @errors = ();
foreach my $file ( @files ) {
open(OLD, "<$file") or push @errors, "failed to open $file: $!";
open(TEMP, ">temp.txt") or push @errors, "failed to create temp
file: $!";
while (my $line = <OLD>) {
$line =~ s/<!\[CDATA\[([^\]]*)\]\]>/$1/ig;

You're reading the file line-by-line here, so the assumption is the CDATA
block is all on one line. I wouldn't think that's a safe assumption to make.
You might want to consider using a real XML parser.

Matt


.



Relevant Pages

  • Help making this script better
    ... I am using Python 2.4, ... can use this script. ... # This sciript will process a directory of XML files and push them to ... def getFiles2Post: ...
    (comp.lang.python)
  • Re: Schedule Ruby Code!
    ... this list in a generated XML files, ... schedule this script to run every 30 minutes. ... script run every 30 minutes, I'm new to the language I liked it and I ... If you want to stay Ruby, you can use the OpenWFEru scheduler and ...
    (comp.lang.ruby)
  • Re: Need a Script to pull specific data from an xml file
    ... I'm a script newbie so any and all help would be greatly appreciated. ... For Each oApp in oApps ... If dApps.Exists("State City") Then ... The other part of your problem is searching a folder for XML files, ...
    (microsoft.public.windows.server.scripting)
  • Perl script does not work
    ... I am trying hard to run this script on fedora 3 ... It changes the following pattern in xml files ... Any reasons ... print TEMP $line; ...
    (comp.lang.perl.misc)
  • xml parsing script dying with "Premature end of script headers" error
    ... I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. ... The script has worked well for a couple of years, despite having very crude error-trapping (if it finds an error in one of the xml files, the script stops). ...
    (comp.lang.php)