Loading ...
Sorry, an error occurred while loading the content.
 

RE: [PBML]

Expand Messages
  • Dukelow, Don
    OK to make everthing clear to everyone, this is what I m trying to do. my @menu_list = ( menu item1 , menu item2 , menu item3 ); my @cmd_list = ( cmd1 ,
    Message 1 of 8 , Jul 26, 2007
      OK to make everthing clear to everyone, this is what I'm trying to do.

      my @menu_list = ('menu item1', 'menu item2', 'menu item3');
      my @cmd_list = ('cmd1', 'cmd2', 'cmd3');

      my $answer = &menu(\$menu_list); # This returns a number from 1 to 3
      my $sub_cmd = $cmd_list[$answer - 1];
      &{$sub_cmd}(); # trying to excute
      scalar as command

      -----
      Don Dukelow
      HP UNIX OVO Enrollment
      Hewlett-Packard (Canada) Co.
      e-mail: dukelow@...
      URL: http://www.hp.ca <http://www.hp.ca/>




      ________________________________

      From: perl-beginner@yahoogroups.com
      [mailto:perl-beginner@yahoogroups.com] On Behalf Of Paul Archer
      Sent: Wednesday, July 25, 2007 10:22 AM
      To: perl-beginner@yahoogroups.com
      Subject: Re: [PBML]



      10:02am, Peter L. Berghold wrote:

      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > Dukelow, Don wrote:
      >> I have a sub name inside a variable, how do I execute the sub.
      >
      >
      > You're question is not all that clear to me, but let me play back what
      I
      > think I'm reading:
      >
      > You have a variable such that:
      >
      > my $var1 = sub { print "marine\n"; };
      >
      > or
      >
      > sub marine {
      > print "sandwich\n";
      > }
      >
      > my 4var2 = \&marine;
      >
      > and you want to execute them. It would look like:
      >
      > &{$var1}();
      > &{$var2}{};
      >

      I think he means he has something like:

      sub mysub { ...}

      my $var = "mysub";

      The short answer to that: don't. Look at Peter's examples instead, and
      if
      you have a lot of subroutines that you are picking from with this
      method,
      post the relevant code--chances are that's not the best way to go about
      it.
      (It may be, but probably not.)

      Paul





      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.