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:

my $command = "my \@returnstring = \$d->checklist( text => $text, list + => [ @list ] );";
If I print out the contents of $command I get exactly the line I want to execute, which looks like this:
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 ] ] );
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?

Thanks in advance for any help!


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.