保存Temp Word Perl单引号

时间:2011-05-30 13:43:33

标签: perl temp

我想在临时文件中用单引号保存hello world 我没有单引号打开临时文件hello world show 如何解决这个问题

#!/usr/bin/perl -w
chomp($TMPFILE = `mktemp bumatinaskk.XXXXXXXXXX`);
$echo = "echo \'hello word\' >>$TMPFILE";
system ("$echo");

1 个答案:

答案 0 :(得分:5)

use 5.010;
use strict;
use warnings FATAL => 'all';
use autodie;
use File::Temp qw(tempfile);
use IO::File qw();

my ($file_handle, $file_name) = tempfile('bumatinaskk.XXXXXXXXXX', UNLINK => 1);
$file_handle->say(q{'hello world'});
$file_handle->close;
say "wrote into temporary file $file_name";

sleep 30;   # giving you some time to inspect the temporary file

END { say 'temporary file is going to be deleted now' }

文档:File::TempIO::File