How do I return the Perl return value to arrayref?

I try the code as follows:

my @rows = getRows($sth); $self->stash(rows => \@rows); 

getRows is the name of the subfunction, and the code works in the template. $ Rows is an array.

I write the code as follows:

 $self->stash(rows => \getRows($sth)); 

$ rows is REF, this is wrong.

If you write code like this:

 $self->stash(rows => getRows($sth)); 

$ rows is HASH, this is wrong.

Is there a way to write two string codes in one?

+6
source share
1 answer

Yes. You can write

 $self->stash(rows => [getRows($sth)]); 

The square brackets [] are used to create the desired link.

+14
source

Source: https://habr.com/ru/post/922133/


All Articles