Internal limit on variable length?

Discussion in 'Perl Misc' started by dn.perl@gmail.com, Aug 26, 2008.

  1. Guest

    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?
    , Aug 26, 2008
    #1
    1. Advertising

  2. Bill H Guest

    On Aug 26, 7:10 am, "" <> 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?


    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
    Bill H, Aug 26, 2008
    #2
    1. Advertising

  3. "" <> wrote:
    >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
    Jürgen Exner, Aug 26, 2008
    #3
  4. Willem Guest

    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
    Willem, Aug 26, 2008
    #4
  5. Bill H <> wrote:
    >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
    Jürgen Exner, Aug 26, 2008
    #5
  6. Guest

    "" <> 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 $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.
    , Aug 26, 2008
    #6
  7. nntpman68 Guest

    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


    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?
    >
    >
    nntpman68, Aug 26, 2008
    #7
  8. Guest

    On Aug 26, 4:10 am, "" <> 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?
    >


    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.
    , Aug 29, 2008
    #8
  9. On 2008-08-29 05:26, <> wrote:
    > 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
    Peter J. Holzer, Aug 29, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rahul Aggarwal
    Replies:
    3
    Views:
    4,502
    Netsharp Ninja
    Apr 6, 2004
  2. vadim
    Replies:
    0
    Views:
    470
    vadim
    May 20, 2004
  3. Replies:
    1
    Views:
    1,076
    Victor Bazarov
    Jun 28, 2005
  4. Aryeh M. Friedman

    max internal length of String

    Aryeh M. Friedman, Jul 27, 2009, in forum: Java
    Replies:
    9
    Views:
    376
    Mike Schilling
    Jul 29, 2009
  5. c676228
    Replies:
    6
    Views:
    155
    Steven Cheng[MSFT]
    Feb 14, 2007
Loading...

Share This Page