passing temp file names to another script

Austin Schutz tex at off.org
Sat Dec 2 16:33:52 CST 2000


On Sat, Dec 02, 2000 at 12:13:03PM -0800, Tom Keller wrote:
> Greetings,
> I am creating a temp file with some "current" data in it. I want another script to have access to this temp file. How do I give the second script the filename?
> 
> I create the temp file using IO::File
> $fh = IO::File->new_tmpfile    or die;
> then write the data to $fh.
> 
> How do I get the temp file name to another script?
> 
	Here's a bad answer:

	
	# Returns hashref w/ each file being a key that has a value of 1.
	sub get_open_files {
        	my($filenames) = {}; 
		my(@lsof_open_files) = `lsof -p $$`;
		shift @lsof_open_files;
		for(@lsof_open_files) {
			chomp;
			$filenames->{(split(/\s+/, $_))[8]} = 1;
		}
		return $filenames;
	}

	my($before_open_files) = get_open_files();
	$fh = IO::File->new_tmpfile    or die;
	my($after_open_files) = get_open_files();
	my($tmp_file_name);
	for(keys(%$after_open_files)) {
		if(! exists($before_open_files->{$_})) {
			$tmp_file_name = $_;
			last;
		}
	}
	print "File opened is: $tmp_file_name\n";

	No, I haven't actually tried to run this. But is seems like it would
work in theory.

	I'm sure there's some magical way of doing this but I wouldn't know
what.

	Austin

TIMTOWTDI



More information about the Pdx-pm-list mailing list