You hit the nail right on the head... I had the second, but Dumper \@a instead of Dumper $a[0], and my test code was assuming I was returning a list. Hate it when that happens ;-)
OK, so now at least I have it returning something sensible, which is always good. In which case, the question is why does this:
AV *
readdir_inode(dirname)
char* dirname
INIT:
struct dirent *ent;
DIR* dir;
SV* record[2];
AV *entry, *ret_val;
CODE:
RETVAL = newAV();
dir = opendir(dirname);
if (!dir)
perror("Cannot open dir");
while ((ent=readdir(dir))) {
printf("%ld %x\n", ent->d_ino, ent->d_name);
record[0] = newSVpv(ent->d_name, 0);
record[1] = newSViv((IV)ent->d_ino);
entry = av_make(2, record);
av_push(RETVAL, newRV_inc((SV*) entry));
}
closedir(dir);
/*RETVAL=*ret_val;*/
/*RETVAL=newRV_inc((SV*) ret_val);*/
OUTPUT:
RETVAL
Return an extra level of arrays?
The calling code:
my @ents = readdir_inode(".");
print Dumper @ents;
The output:
$VAR1 = [
[
'.',
67586
],
[
'..',
255604
...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.