473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Putting code in a variable and running interactively?

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
Jul 19 '05 #1
2 4861
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
Jul 19 '05 #2
Jimmy Phillips <se****@spammers.com> wrote in message news:<pa****************************@spammers.com> ...
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.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric Kincl | last post by:
Hello, its been a while since I posted/looked here... my normal email client doesn't handle newsgroups :( (ximian evolution) I was wondering how you stick a file into a database, and then...
4
by: Dado | last post by:
I lost the point: What is purpose of putting objects to null: If I make a class, JFrame for example, with button which start connection dialog, which is class with connection and statement...
8
by: beliavsky | last post by:
If I have some debugging code in a Python program (mostly print statements) and I want to turn it "off", two obvious methods are to (1) comment out the code (2) set a logical 'debug' variable at...
1
by: Haibao Tang | last post by:
Hail Python pals! I played with the R (http://r-project.cran.org) last night to do some statistics and it has an interactive session too, and I found a feature that is quite useful. I found by...
20
by: Lucas Raab | last post by:
I'm done porting the C code, but now when running the script I continually run into problems with lists. I tried appending and extending the lists, but with no avail. Any help is much appreciated...
17
by: George Sakkis | last post by:
Is there a general way of injecting code into a function, typically before and/or after the existing code ? I know that for most purposes, an OO solution, such as the template pattern, is a cleaner...
6
by: Scott Simpson | last post by:
What is a good tool for running XPath queries on Linux? I have the O'Reilly XPath book and I'm using XPath Visualizer on Windows and that seems to work fine, but I'm looking for something on Linux....
7
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that...
2
by: David Sanders | last post by:
Hi, I have a script with function definitions which I load into ipython for interactive use. These functions modify a global numpy array, whose size I need to be able to change interactively. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.