Hein van den Heuvel
Honored Contributor

Re: While Loop Question?

>> I want that to happen to the interim file and as well as target xml file. (as described in the "cp" and "mv" commands above).


You want to try to use the perl command "rename"
Ir you can call: system(qq(cp.... ))


>> How do I specify the following variables in the Perl script -
env=`hostname |awk -F"." '{print $2}'` # so that the script run in any environment

There is a perl module for that:
Try this: perl -e "use Sys::Hostname; print hostname"

So just use the function 'hostname' in the program, after declaring it from "Sys"

>> destination_xml="/a/g/m/admin.xml" #target xml

Just a piece of string.

>> DATE=`date '+%Y%m%H%M'`

There is a locasltim function for that:

perl -e '($sec,$min,$hour,$mday,$mon,$year)=localtime; printf qq(%d%02d%02d%02d\n),$year+1900,$mon+1,$day,$hour,$min'


>> Also I would like to handle a failure condition wherein if the input file is empty then it should use the previously saved input file...

You could protect that with some defensive shell code before calling perl.
Of, in the perl script you couls explicitly create the output only if data exists.

Tou can pre-test with the '-s ' function,
or you can loop and only open on first data"

While (<>) {
open $out,">x.x" unless $out
:
}


Good luck!
Hein