Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

while loop error 1

Status
Not open for further replies.

arcnon

Programmer
Aug 12, 2003
242
0
0
US
@structure = ('test,test,n','test,test,n','test,test,n','test,test,n','test,test,n');

while ($condition > 0){

$loop_again = 0;

foreach $item (@structure){
@data_info = split(/,/, $item);

if ($data_info[2] eq "n"){
$loop_again = 1;
last;
}
}
if ($loop_again == 1){
#####@structure = get_structure1(@structure);
}else{
$condition = -1;
}
$condition = 1;
}

when then code is ran it throws an error:
Use of uninitialized value in numeric gt (>) at ./test.pl line 123.

Why is it throwing a error and how do I fix it.
 
arcnon, look again at the contents of $structure, I'm not sure you need or want the single quotes in there.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Which line is 123? Is $condition initialized when you enter the while loop?
 
the array is fiction. I added the line so you counld get a idea of what data is in the @structure.

line 123 =>  while ($condition > 0){

what I am trying to accomplish is

while the last data segment, $data_info[2] (which is split from @structure) equals n then process the @structure again
with the sub get_structure1(@structure).

hope this makes it more clear
 
That looks more like a warning than an error, mose likely from
Code:
#!/usr/bin/perl [b][COLOR=green]-w[/color][/b]
Set the value $condition before entering the loop

HTH
--Paul
 
You can also get rid of the warning by instead using the condition:
Code:
while ($condition) {
}

To exit you'd set $condition to 0 instead of -1. Or you could set it to undef
 
yes it is a warning but in my minds eye if it is a warning by symantics I consider it a error and I try to fix the problem.

it isn't in my code snippet but I have $condition set before it hits the while loop

The thing is when I get the warning/error:
value in numeric gt (>)
that means I am trying to evaluate it as string and not a value

when I change it to a string I get a warning:
value in string > (gt)
which is the opposite

anyways thanks for the help guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top