Welcome to iraf.net Friday, May 17 2024 @ 02:44 AM GMT


 Forum Index > Help Desk > Systems New Topic Post Reply
 resetting variable
   
Haplo
 02/26/2009 03:10PM (Read 5478 times)  
+----
Newbie

Status: offline


Registered: 02/26/2009
Posts: 3
Is it possible to reset a boolean variable, after it was assigned a value?I have this (see below) construct to prematurely end a script and the answer "yes" is unfortunatly remembered... So it only works as intended the first time in the script, and on every next occurence "yes" is automatically implied...This is the code:
[code:1:1c7506e712]print ("Do you want to continue? (yes/no)")
junk = scan (answer)
if (answer == yes) {
}
else {
bye()
}[/code:1:1c7506e712]
I tried [code:1:1c7506e712]answer = ""[/code:1:1c7506e712], but this gave me an "ERROR: Non-boolean operand used where boolean expected".

 
Profile Email
 Quote
fitz
 02/26/2009 03:10PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
[quote:64a27a14fb]
I tried
Code:
answer = ""
, but this gave me an "ERROR: Non-boolean operand used where boolean expected".[/quote:64a27a14fb]This is because you were setting the value to a null string, which is not a legal boolean value. If you need to reset the value to something other than yes/no to indicate it isn't set, you can use INDEF, e.g.[code:1:64a27a14fb]answer = INDEF
if (isindef (answer)) {
....set the value
} else {
....do something with it
}
[/code:1:64a27a14fb]-Mike

 
Profile Email
 Quote
Haplo
 02/26/2009 03:10PM  
+----
Newbie

Status: offline


Registered: 02/26/2009
Posts: 3
Thanks for the quick reply, but maybe I didn't understand you correctly, but this is still not working. I have this new code:
[code:1:4dd831260a]answer = INDEF
if (isindef (answer)) {
junk = scan (answer)
if (answer == yes) {
}
else {
bye()
}
}[/code:1:4dd831260a]The cl always goes into the "else" loop, because the "scan (answer)"-part is never executed - probably because he still thinks INDEF is a defined value (which would be rather ironic)...
Could you further elaborate the "....set the value"-part of your suggestion?Thanks again!

 
Profile Email
 Quote
fitz
 02/26/2009 03:10PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
Is this a procedure script or are you running it as e.g. "cl<script.cl" ? The scan() should always be executed, but it's looking to read the value from the standard input and if you're redirecting the input the scan may not be succeeding as expected. Is there more to the script that prints a prompt string of some kind?As for "...set the value", all I mean is that if you detect an INDEF value you could do something to reset the value, e.g. print a prompt and scan for the answer, so you can keep processing. I was simply trying to show how to set a boolean variable to INDEF, and then how to detect that within the script.-Mike

 
Profile Email
 Quote
Haplo
 02/26/2009 03:10PM  
+----
Newbie

Status: offline


Registered: 02/26/2009
Posts: 3
Sorry for the long delay in answering (I had a week off)...I run the script from the command line - "cl < script.cl".When I run the modified script as it is shown below, the script never waits for the user input for "scan (answer)". I still presume it somehow accepts "INDEF" as a set value and does not prompt for a new one...Here is the complete script:
[code:1:a5bfed3de7]string *dlist
string currdir,startdir
bool answer
int junkls -d */ > directories
dlist = "directories"
pwd | scan (startdir)while (fscan (dlist, currdir) != EOF) {
cd (currdir//"/images")
if (!access ("../varstars.ds9")) {
display ("ref.fits", 1, >& "dev$null")
print ("Do you want to continue? (yes/no)")
answer = INDEF
if (isindef (answer)) {
junk = scan (answer)
if (answer == yes) {
}
else {
cd (startdir)
dlist = ""
bye()
}
}
}
;
cd (startdir)
}[/code:1:a5bfed3de7]Thank you for your input!

 
Profile Email
 Quote
   
Content generated in: 0.12 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login