mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:
I'm using File::Temp::tempfile to get a name to use for a temporary file to temporary output from a piped command. The book Programming Perl, 4th ed. mentions that it is prefereable to use the file handle that the tempfile() function creates instead of the file name. Is there any way to do that in the context of the code snippet below?
my ($handle, $output) = tempfile("tidyXXXXXX", DIR => "/run/validator", SUFFIX => ".dat" ); my $tidy = q(/usr/bin/tidy); my @args = ('-quiet', '-xml', '-file', $output); # process web page with tidy open(TIDY, "-|", $tidy, @args, $tempfile) or die("Could not open '$tidy' : $!\n"); close(TIDY);
What about other improvements to the above?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Temp::tempfile : name versus handle
by haukex (Archbishop) on Mar 22, 2018 at 13:22 UTC | |
by mldvx4 (Hermit) on Mar 22, 2018 at 15:21 UTC | |
by haukex (Archbishop) on Mar 22, 2018 at 21:25 UTC | |
by marto (Cardinal) on Mar 22, 2018 at 15:29 UTC | |
by mldvx4 (Hermit) on Mar 22, 2018 at 15:45 UTC | |
by marto (Cardinal) on Mar 22, 2018 at 15:54 UTC | |
|
Re: File::Temp::tempfile : name versus handle
by ikegami (Patriarch) on Mar 22, 2018 at 16:25 UTC | |
by mldvx4 (Hermit) on Mar 22, 2018 at 19:09 UTC | |
|
Re: File::Temp::tempfile : name versus handle
by thanos1983 (Parson) on Mar 22, 2018 at 16:10 UTC | |
|
Re: File::Temp::tempfile : name versus handle
by karlgoethebier (Abbot) on Mar 23, 2018 at 12:55 UTC |