Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Small examples of string eval

by DrHyde (Prior)
on May 15, 2006 at 09:22 UTC ( #549412=note: print w/replies, xml ) Need Help??


in reply to Small examples of string eval

Here's an example I wrote. It's in use in production code. The method that contains this is a "helper" method which lives in its own package and is used in several classes. It mangles some paramaters and then:
  • changes package to whatever class it was invoked from;
  • calls a method in that class's superclass.
The reason I need to change package halfway through the method is, from perldoc perlobj:
It is important to note that "SUPER" refers to the super-class(es) of the current package
so instead of just doing this:
$class->SUPER::blah($hash_of_data);
I have to do this:
eval " package $class; \$class->SUPER::blah(\$hash_of_data); ";
Block eval won't cut it here, and while I'm sure plenty of people are going to bleat that this travesty just demonstrates that my design was wrong in the first place (and I'd agree) in the real world one doesn't always know what all the requirements are when one starts writing code. I decided it was better to write a couple of lines of ugly code - and comment what I was doing and why - than to spend literally days re-jigging everything else so that I could then write that tiny snippet of functionality more cleanly.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://549412]
help
Chatterbox?
[Lady_Aleena]: pcre stands for 'Perl Compatible Regular Expressions'.
[erix]: ok, ok, I thought you meant the engine
[perldigious]: Tanktalus: Ha, understandable, that does make it harder when you don't want to move. I assume you are looking at remote work from home jobs too?
[Tanktalus]: yeah, I'm looking at a lot of remote work - I've been working from home since 2002, so I know how to do the work from remote, I just need a new employer ;)
[Lady_Aleena]: Discipulus, I wouldn't know how to get a script to do what the greps do in one line.
[perldigious]: Even working for a large software engineering contractor that's willing to do remote could be an option. The fortune 500 company at $job-- I worked for had quite a lot of that work to hire out to large contractors.
[perldigious]: The pay and benifits leave a lot to be desired though, or so I've heard...
[Lady_Aleena]: Discipulus, grep doesn't have an option to go recursively through a directory as far as I know.
[Your Mother]: I work remotely and my pay and benefits are quite nice. :P
[choroba]: Lady_Aleena Perl's grep is not related to directories

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2017-05-23 19:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?