2011-05-30 33 views
0

我試圖拯救世界您好,在臨時文件 我打開臨時文件的Hello World節目單引號,而不單引號 如何解決這個保存臨時數據字的Perl單引號

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

1)你應該把「嚴格使用」。在你所有的Perl程序中。 2)嘗試打印($ echo)以查看你在那裏放置了什麼(然後修復它,以便在那裏放置你真正打算放在那裏的內容) – tadmc 2011-05-30 14:35:02

回答

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