I writing programing with Perl and XS. I need to display and do some operations that use a linked list from C. How can I accomplish that?
我用Perl和XS编写编程。我需要显示并执行一些使用C中链接列表的操作。我该如何实现?
3 个解决方案
#1
I have to say you could have provided a bit more information to make it easier for people to help you.
我不得不说你可以提供更多信息,让人们更容易帮助你。
Anyway. Despite the age, I would suggest you look at the CookBookA and CookBookB examples in Dean Roehrich's CPAN directory. Specifically, in the CookBookB set, you will find an example that does exactly what you ask for: 'ListOfStruct'.
无论如何。尽管年代久远,我建议您查看Dean Roehrich的CPAN目录中的CookBookA和CookBookB示例。具体来说,在CookBookB集中,您将找到一个完全符合您要求的示例:'ListOfStruct'。
#2
Write a C function to serialize the linked list as a string, or better yet write a set of functions: new_list, destroy_list, add_item, remove_item, walk_list (should take a function reference and call it on each item in the list). Then you could say things like:
编写一个C函数来将链表序列化为字符串,或者更好地编写一组函数:new_list,destroy_list,add_item,remove_item,walk_list(应该采用函数引用并在列表中的每个项上调用它)。然后你可以这样说:
my $list = $new_list;
add_item $list, 5;
add_item $list, 6;
add_item $list, 7;
walk_list $list, sub { print $_[0] }; #prints 567
destroy_list $list;
#1
I have to say you could have provided a bit more information to make it easier for people to help you.
我不得不说你可以提供更多信息,让人们更容易帮助你。
Anyway. Despite the age, I would suggest you look at the CookBookA and CookBookB examples in Dean Roehrich's CPAN directory. Specifically, in the CookBookB set, you will find an example that does exactly what you ask for: 'ListOfStruct'.
无论如何。尽管年代久远,我建议您查看Dean Roehrich的CPAN目录中的CookBookA和CookBookB示例。具体来说,在CookBookB集中,您将找到一个完全符合您要求的示例:'ListOfStruct'。
#2
Write a C function to serialize the linked list as a string, or better yet write a set of functions: new_list, destroy_list, add_item, remove_item, walk_list (should take a function reference and call it on each item in the list). Then you could say things like:
编写一个C函数来将链表序列化为字符串,或者更好地编写一组函数:new_list,destroy_list,add_item,remove_item,walk_list(应该采用函数引用并在列表中的每个项上调用它)。然后你可以这样说:
my $list = $new_list;
add_item $list, 5;
add_item $list, 6;
add_item $list, 7;
walk_list $list, sub { print $_[0] }; #prints 567
destroy_list $list;