perl references in a while loop
while (0..25) {
$x++;
$d[$t++]=\$x;
until ($x < 25) {
lable:
print "hello::","\n";
$in = STDIN;
print ${$d[$in]};
goto lable;
}
}
## now this should print 1 when i type 1
## and 2 when I type 2 at
## and 3 when I type 3 instead it types 25
## for 1 to 25 typed in
## plese help
while (0..25) {
$x++;
$d[$t++]=\$x;
until ($x
lable:print "hello","\n";
$in = ;
print ${$d[$in]}; goto lable; }}
## why wont this work !!!... ???
Whatever it is you want it to do, you're doing it all wrong.
The range in the while loop always returns true, which means that the while loop is never exited.
untilis checked to see if the statement is false and so is equivalent tothe
lable:andgoto lable;is an additional loop inside the until loop. Since the$xvariable is never decremented inside the until loop, it would never be exited, so the goto loop is superfluous.Assuming that STDIN is actually enclosed in angle brackets, your main problem, however, is that you are assigning a reference to
$xto all of the@dindexes from 0 to 24. (If you type in 25, you won't get 25, you'll get undefined.) A reference means that you get what$xis when you dereference the array slot and not what it was when you assigned it., that's what you'll get for every index of @d from 1 to 24. Since the last thing$xwas assigned was 25Probably the code you want is: