Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > List::MoreUtils::each_arrayref: "semi-panic: attempt to dup freed string"

Reply
Thread Tools

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

 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      02-25-2006
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

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      02-25-2006

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 >

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      02-25-2006

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


 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      02-25-2006
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

 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      02-25-2006
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=71423350343770280161397026330337371139054411854 220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($ m+=<=200);
 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      02-25-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rubyzip - `dup': can't dup NilClass (TypeError) Luka Stolyarov Ruby 10 09-11-2010 12:13 PM
:s.respond_to?(:dup) && :s.dup raises François Beausoleil Ruby 1 04-05-2007 05:55 PM
the ASP .NET output cache gets freed up ..... dg ASP .Net 0 09-28-2005 04:46 PM
Can't locate object method "first" via package "attempt" (perhaps you forgot to load "attempt"?) at .... GMI Perl Misc 3 06-19-2005 10:44 PM
Two Questions: Word document 'in use' - can they be freed? AND Win2K Server admin. Andy½ Computer Support 2 04-02-2004 07:41 AM



Advertisments