I'm trying to write a perl script that I can run as a cron job in root of my web server that will look for .shtml files get their last modified date and replace it in the sitemap_test.xml file. the problem is the substitution doesn't work and when I print to MYFILE it adds the lastmod to the end of the file. Any help would be appreciated.
(a) Your program is quite inefficient since it populates the array "@shtml_files" and then parses the entire file for each array element. If your array has, say, 100 elements then you'll be opening, parsing and closing the "sitemap_test.xml" file 100 times.
(b) A more efficient way would be to populate the array and then walk through the xml file just once. Whenever you encounter the <loc> tag in the file, look up the filename in the array. You can use "grep" operator for that. (Perl 6 will have an operator to emulate "in" i.e. "element x in <array>" that you find in awk/pascal/sql etc.)
(c) The in-place modification of the xml file via the update mode ("+<") works well for small files, but doesn't scale well. For huge files, it could jam your system's virtual memory. Instead, use a temporary file that uses much less memory and creates a backup file.
Here's the updated script that implements all the thoughts above -
Thank You Tyler and Deindorfer, I knew there was a more efficient solution than my amateur effort. I'll try both of these and have already learned a lot about scripting in perl. Thanks again for your time and effort helping me out.
Below is the content in my XML file
<name>XXX</name>
<eventType>Uptime</eventType>
<eventType>Delay</eventType>
<eventType>Delay</eventType>
<name>YYY</name>
<eventType>Uptime</eventType>
<eventType>Delay</eventType>
... (12 Replies)
Good Day All
Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1".
I need to to create a script that... (2 Replies)
Hi Everyone,
I'm new here and I was checking this old post:
/shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html
(cannot paste link because of lack of points)
I need to do something like this but understand very little of perl.
I also check... (4 Replies)
we have a CSV which i need to convert to XML using Perl or Unix shell scripting.
I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Hi,
I have a xml file that I need to modify 1 line to change some value from 2 to 10 (or any number).
Sample input:
<!-- some text here>
.
.
.
<message:test name="ryan">
<message:sample-channel charset="UTF-8" max-value="2" wait="20">
... (5 Replies)
Hello,
I have a XML file and need to update the data for a specific XML Attribute in the file. I need a Perl or Awk command to look for <INTERCHANGE_CONTROL_NO>000000601</INTERCHANGE_CONTROL_NO>
in the XML file and change the first two 0 of the value to 9.
For instance ... (4 Replies)
Hi experts,
I have a set of xml files in folder which has the below field.
<mm:sessionID>157.235.206.12900397BE4:A</mm:sessionID>,
I need to update this field regularly with new session id, which I have it from a login file.
Can anyone tell me how to add a new value in <mm:sessionID>... (3 Replies)
I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)