Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Probably an easy one - store command in variable.

by injunjoel (Priest)
on Sep 15, 2005 at 19:36 UTC ( #492402=note: print w/replies, xml ) Need Help??


in reply to Probably an easy one - store command in variable.

Greetings all,
I agree with Roy Johnson about the slashes. you are trying to make @results a reference on the left hand side, which is why you are getting the error.
Here are my suggestions for modifying your code.
my $command = sub { my @returnstring = $d->checklist( text => $text, list => [ @list ] + ); return \@returnstring; }; my $some_ref = &$command;
Now if you wanted the array from $d->checklist() to return as a reference itself you might try.
my $command = sub { my $returnstring = \($d->checklist( text => $text, list => [ @list + ] )); return $returnstring; }; my $some_ref = &$command;
However if you already have declared @returnstring outside of the scope of your anonymous sub and you wish to use this sub to modify it then you could simply do something like this...
my @returnstring; my $command = sub { @returnstring = $d->checklist( text => $text, list => [ @list ] ); };
again assuming that $d->checklist() returns an array.
A simple way to think of it is that references get assigned to something. So the \ is allowed on the right hand side only.
At least thats what works for me. :)
These examples are untested but I think, as Roy Johnson pointed out, that your slashes are the problem.

-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492402]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-07-17 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?