How to retain a value in variable for consecutive execution of the pl script - perl

I am new to perl scripting. Need your suggestion for the same
I have a xyz.pl script which runs to success or failure. If it fails, I need to save the checkpoint where it failed e.g. the failure name in a variable
$var=job[0];
When I rerun xyz.pl for the second time, it should read this variable $var and picks its value and start from job where it failed and not from the beginning.
In perl, is it possible? Is there variable which can retain the value for the above scenario for consecutive runs of the script.
Please advise.

A variable cannot survive the end of a script. However, you can save the value into a file from which you can later read it back into another run of the script.

Related

Every last itteration failing in start loop stage

I have created a genric sequence job.
Exec command >> start loop >> job activity >> end loop
Here in exec command stage i have written a script to get list of files present in directory as csv values, and the file count will varry.
file,file2,file3
But when i run the job every last itteration fails showing below error
#job_activity,error calling DSSetParam(name), code =-4
Not sure if you figured it out yet, but I was having the same problem. Per one of your comments about handling the #FM, are you doing that inside an Ereplace function (e.g., Ereplace(<string>,#FM,'')?
I had this in my StartLoop activity and after trying several different things, I fixed the issue by adding a new UserVariables activity in-between the command and loop and moving the Ereplace function to it and then using the new user variable as the list in the loop.
Assuming this works for you too, your new flow will look something like this: exec command (where you pull the list and nothing more) >> user variables (create one variable with the Ereplace(<name>.$CommandOutput,#FM,'') [replace the name with whatever you called your exec command] in the expression) >> start loop >> job activity >> end loop.
I haven't been able to find anything from IBM as to why adding that extra step works (hopefully someone else is more successful), but it's what did the trick for me.
Hope that helps.

What is the command and syntax for breaking/stopping a program in QBASIC?

I am currently writing a QBASIC program that runs an indefinite loop (while loop). However, if a certain condition is met, I want to exit the program. What command do I use, and also what is the syntax.
Thanks
ENDexits program, and clears all variables, which frees up memory.
STOPexits program, but retains the value of all variables, which makes it possible (in certain versions of QB) to continue execution at another point, by choosing Set next statement from the Debugmenu, and then Startfrom the Runmenu. END has the same effect as STOP + choosing Restart from the Runmenu once the program has terminated.
If you have a loop, and want to exit the program from inside it, you may use either
DO
IF condition THEN EXIT DO
LOOP
END
or
DO
IF condition THEN END
LOOP
You're looking for the END or SYSTEM statement. For example:
PRINT "Hello World!"
END
PRINT "This won't be printed."
If you're using regular old QBASIC/QuickBASIC, then you can ignore all of the QB64 details on the linked pages and just use either SYSTEM or END. Both will do the same thing for the most part.1
If you're using FreeBASIC, it's recommended to use END instead of SYSTEM since some things won't get cleaned up properly when you use SYSTEM. See SYSTEM for more information pertaining to FreeBASIC if that's what you're using.
1 The END statement when running the program using QB.EXE /RUN PROGRAM.BAS will print "Press any key to continue" before exiting to the QB/QBASIC environment. The SYSTEM statement when run the same way will simply return you to the DOS shell without any need for a key press. Also, typing SYSTEM in the "Immediate Window" of the QB/QBASIC environment will exit the environment and return to the DOS shell. Otherwise the two statements behave exactly the same in QB/QBASIC, whether for standalone (compiled) programs or .BAS modules.
You can keep any condition according to the need of your program. For eg:
CLS
LET a = 5
WHILE a > 0
PRINT a;
a = a - 1
WEND
END
Here, in the program while wends executes itself until a = 0. This will not run an infinite loop.
The answer is
exit();
to exit the program.

same input for interactive command in Perl script

In Perl script I am using command of unit(external command) using system
but that command need some run time input from user. Every time I want to give similar input which is stored in variable.
My command is:
system("dt ci $dest_file");
after this command my script is waiting for user input,
lets say I want to give "re base" as input to this every time
How can I give fix input every time it asks?
Please help, I am working on windows 7.
I want to make script completely automated... it should not wait for user input
If you call your script like this:
perl test.pl < input.txt
It should take the content of the file as an input. ( this is working with STDIN read )

Easytrieve A010 invalid file reference

I am getting the error in this line of my easytrieve prog..
JOB INPUT NULL MASTER-FILE
GET DATAPRM <~~~~~~~ LINE 59
DO WHILE NO EOF DATAPRM
...
GET DATAPRM
END-DO
..
59******A010 INVALID FILE REFERENCE - DATAPRM
..
I have a DLBL like this ..
//DLBL DATAPRM, 'DATAPRM.SAM'
I am trying to populate the masterfile by data using the input file DATAPRM (card) .. the records were being read(i assume since my counter is moving) but unfortunately, before it terminates the program, the error occurs.. maybe EOF?
You have no STOP in your program. Not just in the code that you have shown, but anywhere. Or if you do, it is conditional and the condition was not met.
Easytrieve Plus does an "automatic cycle". Usually with the file named on the JOB statement, but when NULL is specified, it just cycles from the last statement in the JOB through to the JOB again.
After you get to EOF in your DO, you need to STOP when you have finished everything else. What is happening now is you are getting EOF, getting out of the DO, cycling to the top again (the JOB), and then it does a GET, after EOF, so ******A010 INVALID FILE REFERENCE - DATAPRM

How to search for a particular string and goto sleep if not found in perl?

I have two test cases in log file ActivateJob and GetJOBStatus as below, my perl script currently set to PASS as default and it searches for Error in the below test cases, if it finds error in the below it makes test case as FAIL. For GetJOBStatus test case if it is ACTIVE script as to sleep for couple of mins and it as to perform GetJOBStatus again and if it is success test case as to be passed or else fail. How can i perform sleep and search for active in GetJOBStatus test case.. ply help me out... thanks in advance..
==============log file===================
Date and Time is:Thu, 20-06-2013 06:04:19
Line 4 Command:ActivateJob(Job=Test_Abort_New1);
Answer:
ActivateFTSJobResult = Success
COMPLETED
Date and Time is:Thu, 20-06-2013 06:04:19
Line 5 Command:GetJOBStatus(Job=Test_Abort_New1);
Answer:
GetJOBStatusResult = NELabel,Status,ErrorReason,Progress,CurrentUnit,Total
TSS_320_1,ACTIVE,No Error,0,BACKUP.DSC,0
COMPLETED
In order to check for a string in a file, you have to
open the file using open
read the file using <>
search the file using m//
close the file
In order to sleep (for a seconds), you have to sleep(a)
Keep in mind that unless you perform seek on your filehandle, you will have to close and then re-open it in order for it to reach the beginning.
As for you specific question, it appears to be implemented as an example in the seek perldoc