List::MoreUtils::each_arrayref: "semi-panic: attempt to dup freed string"

Discussion in 'Perl Misc' started by usenet@DavidFilmer.com, Feb 25, 2006.

  1. Guest

    Kindly consider, if you will, the following code which illustrates my
    question about List::MoreUtils (which reminds me, I haven't seen
    Tassilo around here recently)...

    #!/usr/bin/perl
    use strict; use warnings;
    use List::MoreUtils qw{ each_arrayref };

    my $ea = each_arrayref ([1..26],["A".."Z"]);
    while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    print "$a\t$b\n";
    }
    __END__

    Which is a convoluted way to do this (but I expect the same result):

    perl -e 'printf ("%s\t%s\n", $_, chr($_ + 64)) for (1..26)'

    But instead, I get an error (twice):

    semi-panic: attempt to dup freed string at ./junk line 6.

    That message makes absolutely no sense to me (and it's not explained in
    the docs), and I can't see what's wrong with my code (other than the
    fact that its a convoluted approach).

    If only I knew what I was doing wrong then the color would return to
    the trees and the flowers would regain their fragrance. As it is, I'm
    consigned to a gray world of despair.

    --
    http://DavidFilmer.com
     
    , Feb 25, 2006
    #1
    1. Advertising

  2. wrote:
    > Kindly consider, if you will, the following code which illustrates my
    > question about List::MoreUtils (which reminds me, I haven't seen
    > Tassilo around here recently)...
    >
    > #!/usr/bin/perl
    > use strict; use warnings;
    > use List::MoreUtils qw{ each_arrayref };
    >
    > my $ea = each_arrayref ([1..26],["A".."Z"]);
    > while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    > print "$a\t$b\n";
    > }
    > __END__
    >
    > Which is a convoluted way to do this (but I expect the same result):
    >
    > perl -e 'printf ("%s\t%s\n", $_, chr($_ + 64)) for (1..26)'
    >
    > But instead, I get an error (twice):
    >
    > semi-panic: attempt to dup freed string at ./junk line 6.
    >
    > That message makes absolutely no sense to me (and it's not explained in
    > the docs), and I can't see what's wrong with my code (other than the
    > fact that its a convoluted approach).
    >
    > If only I knew what I was doing wrong then the color would return to
    > the trees and the flowers would regain their fragrance. As it is, I'm
    > consigned to a gray world of despair.


    this should work:
    =====

    my @nums = 1..26;
    my @lets = "A".."Z";

    my $ea = each_arrayref (\@nums,\@lets);
    while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    print "$a\t$b\n";
    }

    __END__
    [nagano 56] ~/simons/1-perl > try_eacharrayref.pl
    1 A
    2 B
    3 C
    4 D
    5 E
    6 F
    7 G
    8 H
    9 I
    10 J
    11 K
    12 L
    13 M
    14 N
    15 O
    16 P
    17 Q
    18 R
    19 S
    20 T
    21 U
    22 V
    23 W
    24 X
    25 Y
    26 Z
    [nagano 57] ~/simons/1-perl >

    ===

    you know what's weird? the following causes a bus core dump:
    ====
    use strict; use warnings;
    use List::MoreUtils qw{ each_arrayref };

    my @nums = 1..26;
    my @lets = "A".."Z";

    my $ea = each_arrayref (\@nums,["A".."Z"]);
    while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    print "$a\t$b\n";
    }

    __END__
    [nagano 53] ~/simons/1-perl > try_eacharrayref.pl
    semi-panic: attempt to dup freed string at ./try_eacharrayref.pl line
    10.
    Use of uninitialized value in concatenation (.) or string at
    ../try_eacharrayref.pl line 11.
    1
    Bus Error (core dumped)
    [nagano 54] ~/simons/1-perl >
     
    it_says_BALLS_on_your forehead, Feb 25, 2006
    #2
    1. Advertising

  3. it_says_BALLS_on_your forehead wrote:
    >
    > this should work:
    > =====


    sorry, i had strict and warnings on in my code, but i missed it when i
    copied:

    use strict; use warnings;

    >
    > my @nums = 1..26;
    > my @lets = "A".."Z";
    >
    > my $ea = each_arrayref (\@nums,\@lets);
    > while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    > print "$a\t$b\n";
    > }
    >
    > __END__
    > [nagano 56] ~/simons/1-perl > try_eacharrayref.pl
    > 1 A
    > 2 B
    > 3 C
    > 4 D
    > 5 E
    > 6 F
    > 7 G
    > 8 H
    > 9 I
    > 10 J
    > 11 K
    > 12 L
    > 13 M
    > 14 N
    > 15 O
    > 16 P
    > 17 Q
    > 18 R
    > 19 S
    > 20 T
    > 21 U
    > 22 V
    > 23 W
    > 24 X
    > 25 Y
    > 26 Z
     
    it_says_BALLS_on_your forehead, Feb 25, 2006
    #3
  4. Guest

    it_says_BALLS_on_your forehead wrote:
    > this should work:
    >
    > my @nums = 1..26;
    > my @lets = "A".."Z";
    >
    > my $ea = each_arrayref (\@nums,\@lets);


    Yeah, I know that would work. But last time I read the perldocs,
    [1..26] was a reference (to an anonymous array). It ought to work in my
    code:

    my $ea = each_arrayref ([1..26],["A".."Z"]);

    and I don't understand why it doesn't :^(

    --
    http://DavidFilmer.com
     
    , Feb 25, 2006
    #4
  5. Also sprach :
    > Kindly consider, if you will, the following code which illustrates my
    > question about List::MoreUtils (which reminds me, I haven't seen
    > Tassilo around here recently)...


    I lurk. :)

    > #!/usr/bin/perl
    > use strict; use warnings;
    > use List::MoreUtils qw{ each_arrayref };
    >
    > my $ea = each_arrayref ([1..26],["A".."Z"]);
    > while ( my ($a, $b) = $ea->() ) { #[this is line 6]
    > print "$a\t$b\n";
    > }
    > __END__
    >
    > Which is a convoluted way to do this (but I expect the same result):
    >
    > perl -e 'printf ("%s\t%s\n", $_, chr($_ + 64)) for (1..26)'
    >
    > But instead, I get an error (twice):
    >
    > semi-panic: attempt to dup freed string at ./junk line 6.
    >
    > That message makes absolutely no sense to me (and it's not explained in
    > the docs), and I can't see what's wrong with my code (other than the
    > fact that its a convoluted approach).


    The code's fine. List::MoreUtils::each_arrayref isn't. :-( And you don't
    see it documented in L::MU's documentation because it shouldn't happen.
    It's an internal warning from perl because I forgot to increase the
    reference-count of the arguments to each_arrayref appropriately.

    > If only I knew what I was doing wrong then the color would return to
    > the trees and the flowers would regain their fragrance. As it is, I'm
    > consigned to a gray world of despair.


    I'll upload 0.18 right away. With the fix therein, your code does what
    you rightly expect it to do.

    Cheers,
    Tassilo
    --
    use bigint;
    $n=71423350343770280161397026330337371139054411854220053437565440;
    $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
     
    Tassilo v. Parseval, Feb 25, 2006
    #5
  6. Guest

    Tassilo v. Parseval wrote:
    > I'll upload 0.18 right away. With the fix therein, your code does what
    > you rightly expect it to do.


    Thanks! Wouldn't it be great if folks who charged large sums of money
    for software were as considerate and responsive as the folks who freely
    give of their time and talent!

    --
    http://DavidFilmer.com
     
    , Feb 25, 2006
    #6
    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. roopa
    Replies:
    6
    Views:
    751
    Jerry Coffin
    Aug 27, 2004
  2. dackz
    Replies:
    0
    Views:
    489
    dackz
    Feb 6, 2007
  3. Debajit Adhikary
    Replies:
    17
    Views:
    690
    Debajit Adhikary
    Oct 18, 2007
  4. OW Ghim Siong
    Replies:
    2
    Views:
    393
    Peter Otten
    Nov 30, 2010
  5. asil klin
    Replies:
    28
    Views:
    1,300
    Andreas Leitgeb
    Mar 5, 2011
Loading...

Share This Page