Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
XP is just a number
 
PerlMonks  

Variable possession after script death

by Mur (Pilgrim)
on Aug 08, 2003 at 15:50 UTC ( #282228=snippet: print w/ replies, xml ) Need Help??

Description: I had a need for functionality I'd written in a stand-alone script. The script read two different databases for the corresponding table, and compared the rows, burping out the primary key of the rows which were identical. But it did so in the form of a formatted report. I really didn't want to rewrite the script to produce a parseable output, nor did I want to write the new script to parse the report. So I had the new script require the old one, and "possess" its variables beyond the grave...
use vars '@keywords';

open(NULL,'/dev/null');
my $h = select(*NULL);

# This script leaves all its results in @keywords,
# and writes a flowery report that we ignore.
require 'other_script.pl';

select($h);
# and @keywords has all the stuff we want.
Comment on Variable possession after script death
Download Code
Re: Variable possession after script death
by RMGir (Parson) on Aug 08, 2003 at 16:30 UTC
    Wow.

    What a hack.

    What a GREAT hack. :)

    I don't need this trick myself at the moment, but I'm going to try to remember it...
    --
    Mike

Re: Variable possession after script death
by Aristotle (Chancellor) on Aug 10, 2003 at 16:54 UTC
    Hmm. How about rewriting the old script so that it consists of one portion that does the work and produces @keywords and another that prints a report? The first part could then be used by both scripts - either as a full blown locally installed module or as a file that's simply required.

    It's always a good idea to separate logic from output, even when you're not creating webpages. *grin*

    Makeshifts last the longest.

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://282228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-04-16 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls