zane has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the Everything Engine to build a searchable photo archive, and have run into the following problem...

I have an "htmlcode" (which means it behaves like a subroutine so far as I can tell) called "showphotogroup()" Here's how I think it works - but this might all just be voodoo.

It takes an array of references to Node objects (each one corresponding to an image), and lists in a table the thumbnail and the annotation associated with each one. This subroutine is being used in several places - on the search page to display results, on a page called "your new photos" which displays any photos you've uploaded in the last 24 hours (so you can annotate them efficiently), and in scrapbooks - collections of photos that someone has put together by hand.

In some of these instances, it works, and in others, it doesn't, so I don't think the problem is in the subroutine itself, but rather in the way I'm calling it. The following version works fine:

my $str; my $GROUP = getNodeWhere("createtime > DATE_SUB(now(),INTERVAL 24 HOUR +) AND author_user = $$USER{user_id}", 'photo', 'photodatetime'); $str .= showphotogroup(@$GROUP); return $str;
I'm still not 100% clear on what the '@$GROUP' means - is it "treat me like an array, even though I'm just a scalar", in which case how does it know where to break things up into the different elements of the array?

The following version does not work:

my $str; my $GROUP = $$NODE{group}; $str .= showphotogroup(@$GROUP); $str;
Instead, I get the error: null: Can't use string ("7557") as a HASH ref while "strict refs" in use

7557 is the node_id ($$NODE{node_id}) of the first node in the list of nodes contained in @$GROUP.)

The simplified version of the showphotogroup() subroutine that I'm using for testing right now, is:

my @GROUP = @_; return "<p><b>No photos to display</b>\n" unless (@GROUP); my $str; $str .= "<ol>"; foreach my $ptolist (@GROUP) { $str .= "<li>".$$ptolist{title}."</li>"; } $str .= "</ol>"; $str;
Enlightenment wholeheartedly appreciated.

Replies are listed 'Best First'.
Re: subroutines and references in Everything
by chromatic (Archbishop) on Feb 11, 2002 at 00:47 UTC
    Nodegroup nodes only contain node_ids in the group field. You need actual nodes. The simplest way to do this is to add a getRef() call in the loop within showphotoGroup():
    foreach my $ptolist (@GROUP) { $ptolist = getRef($ptolist); $str .= "<li>".$$ptolist{title}."</li>"; }
    It won't hurt any nodes you pass in. (You're right about htmlcode nodes being subroutines, in more ways than one.)