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

U

usenet

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.
 
I

it_says_BALLS_on_your forehead

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 >
 
I

it_says_BALLS_on_your forehead

it_says_BALLS_on_your forehead said:
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
 
U

usenet

it_says_BALLS_on_your forehead said:
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 :^(
 
T

Tassilo v. Parseval

Also sprach (e-mail address removed):
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
 
U

usenet

Tassilo said:
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!
 

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

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top