我愿结束科技促发委的工作,以防止我守则产生我需要进一步计算,但我不想在网页上进行计算的具体形象。
因此,我想结束科技促发委的工作,我必须做些什么,然后将科技促发委重新投入到网页上。 <>strong>(无)
我尝试的是:
close STDOUT;
# my code here
open STDOUT;
......
增 编
我愿结束科技促发委的工作,以防止我守则产生我需要进一步计算,但我不想在网页上进行计算的具体形象。
因此,我想结束科技促发委的工作,我必须做些什么,然后将科技促发委重新投入到网页上。 <>strong>(无)
我尝试的是:
close STDOUT;
# my code here
open STDOUT;
......
增 编
解决你的问题有多种途径,其中许多方法并不要求你关闭科技促发委,并有可能破坏贵方案的标准I/O频道。
例如,您可使用http://search.cpan.org/perldoc?perlfunc#select>。 指示<代码>印数/代码>的产出,在其他地方临时指挥。
print $stuff_you_want_to_send_to_STDOUT;
select(NOT_STDOUT);
# now default print sends things to NOT_STDOUT.
# This doesn t need to be a real filehandle, though you may get warning
# messages if it is not.
...;
print $the_image_you_dont_want_to_go_to_STDOUT;
...;
select(STDOUT);
# now print sends things to STDOUT agin
print $more_stuff_you_do_want_to_go_to_STDOUT;
也可在不关闭任何业务的情况下,在运行时间重新安排<条码>* TDglob。
*OLD_STDOUT = *STDOUT;
print $for_STDOUT;
*STDOUT = *NOT_STDOUT; # again, doesn t need to be a real filehandle
print $stuff_to_suppress;
*STDOUT = *OLD_STDOUT; # restore original STDOUT
print $more_stuff_for_STDOUT;
由于很多人认为STDOUT总是开放,因此它不难结束。 最好将其转至<代码>dev/null(unix)或nul
(Windows)。
如果你想要改写,
use Sub::ScopeFinalizer qw( scope_finalizer );
{
open(my $backup_fh, >& , *STDOUT) or die $!;
my $guard = scope_finalizer { open(STDOUT, >& , $backup_fh) or die $!; };
open(STDOUT, > , /dev/null ) or die $!;
...
}
如果你只是想把科技创新的方向转向,
{
local *STDOUT;
open(STDOUT, > , /dev/null ) or die $!;
...
}
如果你只是想调整拖欠的产出处理,
use Sub::ScopeFinalizer qw( scope_finalizer );
{
open(my $null_fh, > , /dev/null ) or die $!;
my $backup_fh = select($null_fh);
my $guard = scope_finalizer { select($backup_fh); };
...
}
你们可以做些什么,以达到科技创新目标:
sub stdout_of (&) {
my $code = shift;
local *STDOUT;
open STDOUT, > , (my $stdout_string = )
or die "reopen STDOUT: $!";
$code->();
return $stdout_string;
}
然后使用:
my $stdout = stdout_of { print "hello world" };
将文件存放在(a)版面,使你能够避免关闭和重新开放STDOUT的陷阱。
(re) 开放STDOUT或STDERR,作为中间文件,首先关闭:
close STDOUT;
open STDOUT, > , $variable or die "Can t open STDOUT: $!";
From the perl doc: http://perldoc.perl.org/functions/open.html You have a : after your close, don t do that. The open above should also work with jus
open STDOUT;
http://www.perlmonks.org/?node_id=635010“rel=“nofollow”http://www.perlmonks.org/?node_id=635010。
我检查了两种方式:
select
*OLD_STDOUT = * STDOUT
, and see they are not usable in common case.The reason is these 2 approachs redirect STDOUT only if "print" or something else is used in a Perl Script. But if you use "system()" call or call subscript, their output got to standard STDOUT anyway =((.
My point of view, the indeed solution is to be:
#!/usr/bin/perl -w
my $file1 = "/tmp/out.txt";
my $file2 = "/tmp/err.txt";
open my $oldSTDOUT, ">&STDOUT";
open OLDERR, ">&",*STDERR;
open(STDOUT, ">$file1") or print("Can t redirect stdout: to $file1 ");
open(STDERR, ">$file2") or print("Can t redirect stderr: to $file2 ");
print "THIS OUTPUT ISN T GOT TO STANDARD OUTPUT
";
system("pwd"); # this output isn;t got to standard output too, that is right!
close(STDOUT);
close(STDERR);
open STDOUT, ">>&", $oldSTDOUT;
open STDERR, ">>&OLDERR";
print "BUT THIS OUTPUT IS SEEN IN A STANDARD OUTPUT
";
我检查了这一解决办法,并为我工作。
I am building a Web interface to monitor an embedded system. I have built a Perl script which runs remote commands and gathers output from that system. Now what I need is a Web interface which makes ...
How do I tell what type of value is in a Perl variable? $x might be a scalar, a ref to an array or a ref to a hash (or maybe other things).
When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...
I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...
I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...
I would like to submit a form to a CGI script localy (w3c-markup-validator), but it is too slow using curl and apache, I want to use this CGI script more than 5,000 times in an another script. and ...
So I m running perl 5.10 on a core 2 duo macbook pro compiled with threading support: usethreads=define, useithreads=define. I ve got a simple script to read 4 gzipped files containing aroud 750000 ...
A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...