Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Putting code in a variable and running interactively?

Reply
Thread Tools

Putting code in a variable and running interactively?

 
 
Jimmy Phillips
Guest
Posts: n/a
 
      08-25-2004
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      08-25-2004
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


 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      08-25-2004
Jimmy Phillips <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)> ...
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting a line from a text file into a variable, then moving to nextline Vernon Wenberg III Python 4 10-07-2007 05:40 PM
ftp putting information in a variable Arne Python 1 04-11-2006 09:55 AM
Taking a string from body text and putting into a variable Sherm Pendley Perl Misc 4 06-18-2005 08:31 PM
Putting Current URL in a Session Variable Keith ASP General 4 08-26-2004 12:35 PM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM



Advertisments