![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with Stop Script during shutdown of o/s | shipon_97 | Red Hat | 1 | 08-11-2009 10:27 AM |
| pERL SCRIPT FOR MONITORING DATE/TIME STAMPS FOR START AND STOP OF APPLICAION IN A LOG | FREDDIE091970 | Shell Programming and Scripting | 4 | 03-31-2008 09:59 PM |
| How to stop perl service | rainbow_bean | AIX | 4 | 01-03-2008 03:07 PM |
| how to stop others users to stop viewing what i am doing ? | mobile01 | UNIX for Advanced & Expert Users | 5 | 12-04-2006 08:37 AM |
| ksh/Linux: Variable scoping issue? Pl. help! | jasmeet100 | Shell Programming and Scripting | 2 | 09-30-2005 06:35 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
I can't stop the scoping problem (perl)
I hate to post something so n00bish, but I'm pretty n00bish when it comes to perl so here it goes:
Code:
$var=1;
while(1){
if ($var == 2){
last;
}
$var=2;
}
Code:
while(1){
$var=1;
if ($var == 2){
last;
}
$var=2;
}
update: Title is supposed to be "spot" not "stop" but apparently I'm dyslexic. Last edited by thmnetwork; 5 Days Ago at 12:15 AM.. |
|
||||
|
Code:
$var=1;
while(1){
if ($var == 2){
last;
}
$var=2;
}
1) step 1 var =1 then goes to while loop 2) In the while loop in the first check var != 2 so doesnot get into the if loop then sets var = 2 3) In the next attempt var is 2 goes into if loop and the while loop ends Now lets check the second block of code Code:
while(1){
$var=1;
if ($var == 2){
last;
}
$var=2;
}
2) sets var =2 and then again goes to the while loop begining 3) Now here what is happening is it sets the variable var to 1 again . the condition of var=2 is never met. Hence the infinite loop. Regarding the scope in the first instance if you print var outside the while loop it would be 1 in the second instance depending on where you declared the variable var like my $var will determine the value. HTH, PL |
|
||||
|
thanks, I don't know how I missed that, I was running on fumes at that point of the night. Thanks for indulging me.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|