rementis has asked for the wisdom of the Perl Monks concerning the following question:
OK, I've tried to do this just now using an anonymous subroutine, but I'm getting strange error messages. Here is my code:
my $command = sub { \@returnstring = \$d->checklist( text => $text, li +st => [ @list ] ) }; &$command;
Here is the error:
Can't modify reference constructor in scalar assignment at ./cdialog.p +l line 43, near ") }" Execution of ./cdialog.pl aborted due to compilation errors (#1) (F) You aren't allowed to assign to the item indicated, or otherwi +se try to change it, such as with an auto-increment. Uncaught exception from user code: Can't modify reference constructor in scalar assignment at ./c +dialog.pl line 43, near ") }" Execution of ./cdialog.pl aborted due to compilation errors.
Here's an update:
Here's the code I'm running now:
my $command = sub { $d->checklist( text => $text, list => [ @list ] ); }; my @returnlist = $command->();
And here's the error:
Can't use string (",") as an ARRAY ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.8.3/UI/Dialog/Backend/CDialog +.pm line 581 (#1) (F) Only hard references are allowed by "strict refs". Symbolic references are disallowed. See perlref.
Also, in case it matters, list contains exactly this:
'1' , [ 'item1' , 0 ] , '2' , [ 'item2' , 0 ] , '3' , [ 'item3' , 0 ] , '4' , [ 'item4' , 0 ] , '5' , [ 'item5' , 0 ] , '6' , [ 'item6' , 0 ]Janitor note: Original content follows:
Hello All-Knowing Monks,I need to execute a command that I have built in a variable, like this:
If I print out the contents of $command I get exactly the line I want to execute, which looks like this:my $command = "my \@returnstring = \$d->checklist( text => $text, list + => [ @list ] );";
But if I put $command; on a line by itself, the contents of $command are not executed as a statement. Is there any way to make the contents of $command execute as a statement?my @returnstring = $d->checklist( text => Text, list => [ '1' , [ 'ite +m1' , 0 ] , '2' , [ 'item2' , 0 ] , '3' , [ 'item3' , 0 ] , '4' , [ ' +item4' , 0 ] , '5' , [ 'item5' , 0 ] , '6' , [ 'item6' , 0 ] ] );
Thanks in advance for any help!
|
|---|