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:
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?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;
The following version does not work:
Instead, I get the error: null: Can't use string ("7557") as a HASH ref while "strict refs" in usemy $str; my $GROUP = $$NODE{group}; $str .= showphotogroup(@$GROUP); $str;
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:
Enlightenment wholeheartedly appreciated.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;
In reply to subroutines and references in Everything by zane
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |