Internal limit on variable length?

D

dn.perl

I am feeling somewhat uneasy posting my query because quite likely it
is some other bug which is causing my code to fail and it is only a
matter of time before I discover it; but I have already spent far too
much time debugging it. So I might as well try to cover some
unsuspected source of bug.

The crux of my code is:

my @in_arr ;
foreach my $in(1 .. 10) {
my $in1 = "aabb" ;
my $in2 = "a string longer than 256 chars, say 275 chars" ;
my $in_str = "$in1 \t $in2 " ;
push @in_arr, $in_str ;
}
while (my $out_str = pop @in_arr) {
my ($out1, $out2) = split /\t/ , $out_str ;
print "out1 is $out1, out2 is $out2 \n" ;
}

The script hangs within the while loop. Could it happen if the value
of $out2 exceeds 256 characters at some point(s) during the code-run?
 
B

Bill H

I am feeling somewhat uneasy posting my query because quite likely it
is some other bug which is causing my code to fail and it is only a
matter of time before I discover it; but I have already spent far too
much time debugging it. So I might as well try to cover some
unsuspected source of bug.

The crux of my code is:

my @in_arr ;
foreach my $in(1 .. 10)  {
    my $in1 = "aabb" ;
    my $in2 = "a string longer than 256 chars, say 275 chars" ;
    my  $in_str = "$in1 \t $in2 " ;
    push  @in_arr, $in_str ;}

while (my $out_str = pop @in_arr)  {
    my ($out1, $out2) = split /\t/ , $out_str ;
    print "out1 is $out1, out2 is $out2 \n" ;

}

The script hangs within the while loop. Could it happen if the value
of $out2 exceeds 256 characters at some point(s) during the code-run?

Its early, I havent had my 1st cup of coffee and I could be wrong, but
won't this always be positive and the while loop will never exit?

while (my $out_str = pop @in_arr)

Bill H
 
J

Jürgen Exner

while (my $out_str = pop @in_arr) {
my ($out1, $out2) = split /\t/ , $out_str ;
print "out1 is $out1, out2 is $out2 \n" ;
}

The script hangs within the while loop. Could it happen if the value
of $out2 exceeds 256 characters at some point(s) during the code-run?

There are certainly bugs in perl and and you can never completely rule
them out as the cause. But it is highly unlikely, in particular in your
case, because splitting long strings on tabs is such a standard
operation and so frequently used that most likely someone would have run
into this problem already in the past two decades.

jue
 
W

Willem

(e-mail address removed) wrote:
)
) I am feeling somewhat uneasy posting my query because quite likely it
) is some other bug which is causing my code to fail and it is only a
) matter of time before I discover it; but I have already spent far too
) much time debugging it. So I might as well try to cover some
) unsuspected source of bug.
)
) The crux of my code is:
)
) my @in_arr ;
) foreach my $in(1 .. 10) {
) my $in1 = "aabb" ;
) my $in2 = "a string longer than 256 chars, say 275 chars" ;
) my $in_str = "$in1 \t $in2 " ;
) push @in_arr, $in_str ;
) }
) while (my $out_str = pop @in_arr) {
) my ($out1, $out2) = split /\t/ , $out_str ;
) print "out1 is $out1, out2 is $out2 \n" ;
) }
)
) The script hangs within the while loop. Could it happen if the value
) of $out2 exceeds 256 characters at some point(s) during the code-run?

I copy/pasted the above code and it does not display any weird behaviour,
even if I change the strig $in2 to actually have more than 256 characters.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
J

Jürgen Exner

Bill H said:
Its early, I havent had my 1st cup of coffee and I could be wrong, but
won't this always be positive and the while loop will never exit?

while (my $out_str = pop @in_arr)

It shouldn't:
If there are no elements in the array, returns the undefined
value (although this may happen at other times as well).

undef should evaluate to false in boolean context.

jue
 
X

xhoster

I am feeling somewhat uneasy posting my query because quite likely it
is some other bug which is causing my code to fail and it is only a
matter of time before I discover it; but I have already spent far too
much time debugging it. So I might as well try to cover some
unsuspected source of bug.

The crux of my code is:

my @in_arr ;
foreach my $in(1 .. 10) {
my $in1 = "aabb" ;
my $in2 = "a string longer than 256 chars, say 275 chars" ;

my $in2 = "a string longer than 256 chars, say 275 chars" x 1000;

That is safely greater than 256 chars. And in my hands it doesn't
reproduce your problem.

my $in_str = "$in1 \t $in2 " ;
push @in_arr, $in_str ;
}
while (my $out_str = pop @in_arr) {
my ($out1, $out2) = split /\t/ , $out_str ;
print "out1 is $out1, out2 is $out2 \n" ;
}

The script hangs within the while loop.

Where in the while loop does it hang? Add a print statement as the first
thing in the loop. How many iterations does it do before hanging?
Could it happen if the value
of $out2 exceeds 256 characters at some point(s) during the code-run?

I don't see how that would matter. On linux, I'd "strace" or "ltrace" the
program and see what was the last thing it did before hanging.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
N

nntpman68

Hi,

Could you just copy the exact code snippet that fails?

The problem might be in one of the lines, which you didn't show us.
apart from that I'd suggest like xhoster to use
print statements (and strace if the prints reveal nothing)

If the real code counts for example mnuch higher than 10 in your first
loop, then you could add a print statement of following kind
print "in=$in" if $in % 100; # print $in every 100th time.


bye


N
 
D

dn.perl

I am feeling somewhat uneasy posting my query because quite likely it
is some other bug which is causing my code to fail and it is only a
matter of time before I discover it; but I have already spent far too
much time debugging it. So I might as well try to cover some
unsuspected source of bug.

The crux of my code is:

my @in_arr ;
foreach my $in(1 .. 10) {
my $in1 = "aabb" ;
my $in2 = "a string longer than 256 chars, say 275 chars" ;
my $in_str = "$in1 \t $in2 " ;
push @in_arr, $in_str ;}

while (my $out_str = pop @in_arr) {
my ($out1, $out2) = split /\t/ , $out_str ;
print "out1 is $out1, out2 is $out2 \n" ;

}

The script hangs within the while loop. Could it happen if the value
of $out2 exceeds 256 characters at some point(s)
during the code-run?

As I had suspected, the cause of the bug was something else.

I wanted 4 distinct integers in the range 1 to max_int. The code was
going in infinite loop when max_int = 4, because I was calling
(int(rand($max_int-1)) + 1), and when I changed it to
(int(rand($max_int)) + 1), the bug went away.

But I was suspecting an internal limit on variable-length because a
debug statement was printing partial string and then hanging. At any
rate, my strings were far too small (max length = 400-500) for this to
be the cause. I had some print statements in my code and it was
hanging with output like:

6 values from Store in Connecticut
5 values from Store in New Mexico \t Near Arizona \t S-W US\t etc
52 values from Sto

(not printing beyond 'Sto')...

Thanks to everybody who responded to my query.
 
P

Peter J. Holzer

I had some print statements in my code and it was hanging with output
like:

6 values from Store in Connecticut
5 values from Store in New Mexico \t Near Arizona \t S-W US\t etc
52 values from Sto

(not printing beyond 'Sto')...

When printing debug output to a file (or a pipe) make sure your
filehandle is unbuffered. STDERR is always unbuffered. Use $| or
autoflush for other file handles.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top