Putting code in a variable and running interactively?

Discussion in 'Perl' started by Jimmy Phillips, Aug 25, 2004.

  1. I am fairly new to Perl so I wasn't real sure how to title this.

    I want to build a regex interactively in a program and then run it. So
    far I do it by writing it to a file along with the Perl envelope around it
    then calling it from my program. Works ok but seems clunky. Then I found
    a tutorial about executing perl code in a regular expression but so far it
    hasn't quite worked the way I want.

    So... Is it possible to put a legimate line of Perl code in a variable,
    then (somehow) execute that variable. Sort of like so...

    $z = "Print amount";
    (execute) $z;

    Or put another way. Build program B within program A then run program B
    within the original program A?

    If this was a standard programming environment like Builder or Kylix I
    wouldn't even ask such a rediculous question, but in my so far brief
    experience with Perl I haven't found much it won't to.

    JP
     
    Jimmy Phillips, Aug 25, 2004
    #1
    1. Advertising

  2. Jimmy Phillips wrote:
    > So... Is it possible to put a legimate line of Perl code in a
    > variable, then (somehow) execute that variable. Sort of like so...
    >
    > $z = "Print amount";
    > (execute) $z;


    perldoc -f eval

    jue
     
    Jürgen Exner, Aug 25, 2004
    #2
    1. Advertising

  3. Jimmy Phillips

    Guest

    Jimmy Phillips <> wrote in message news:<>...
    > I am fairly new to Perl so I wasn't real sure how to title this.


    Actually I would put your subject line in the top 5%. Good subject
    lines are what make Usenet a really useful searchable resource. At
    least they are when you post to newsgroups that actually exist.

    > So... Is it possible to put a legimate line of Perl code in a variable,
    > then (somehow) execute that variable.


    Jürgen has answered that but I'm not sure if you really need to.

    > I want to build a regex interactively in a program and then run it.


    What do you mean by "run it". You don't run regular expressions, you
    use them in m// or s/// or split().

    You can use a calcualated regex directly in a m// or s/// or split() -
    no need to resort to evi^Hal.

    This newsgroup does not exist (see FAQ). Please do not start threads
    here.
     
    , Aug 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MackS
    Replies:
    0
    Views:
    474
    MackS
    Mar 11, 2005
  2. Saurabh
    Replies:
    6
    Views:
    4,571
    Chris Smith
    May 30, 2004
  3. Chris Bingham

    Newbie - Running Commands Interactively

    Chris Bingham, Mar 13, 2006, in forum: Python
    Replies:
    0
    Views:
    267
    Chris Bingham
    Mar 13, 2006
  4. terminus
    Replies:
    0
    Views:
    421
    terminus
    Feb 26, 2008
  5. PerlFAQ Server
    Replies:
    0
    Views:
    99
    PerlFAQ Server
    Feb 19, 2011
Loading...

Share This Page