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

Re: Use a Variable in a Separate Perl Script

by Athanasius (Archbishop)
on Jun 08, 2012 at 16:40 UTC ( [id://975206]=note: print w/replies, xml ) Need Help??


in reply to Use a Variable in a Separate Perl Script

Or just use the ‘obvious’ solution: save $final to a temporary file?

# in Script #1: my $file = 'script1_final.txt'; # add path as required open(my $fh, '>', $file) or die "Cannot open file '$file' for writing: + $!"; print $fh $final; close $fh; # in Script #2: my $file = 'script1_final.txt'; # add path as required open(my $fh, '<', $file) or die "Cannot open file '$file' for reading: + $!"; my $final = <$fh>; close $fh; unlink $file or warn "Cannot delete file '$file': $!"; # Use $final as needed...

The only coupling required here is that the name of the shared file must be known to both scripts.

Not saying this is the best solution, but it does have the virtues of simplicity and extensibility (since it is straightforward to add data to the file if additional data sharing between the scripts is required down the track).

HTH,

Athanasius <°(((><contra mundum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-19 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found