首页 \ 问答 \ Perl的打印功能:打印到最后的文件句柄?(Perl's print function: print to last filehandle?)

Perl的打印功能:打印到最后的文件句柄?(Perl's print function: print to last filehandle?)

我对Perldoc的这一点感到困惑:

如果省略FILEHANDLE,则打印到最后选择的(参见select)输出句柄。 http://perldoc.perl.org/functions/print.html

似乎在写入文件句柄后,一个裸露的print语句将打印到该文件句柄。 我写了一个脚本来测试这个......

#!/usr/bin/perl

open (FILE, '>', 'PrintTest.txt') or die $!;
print FILE "Hello world!\n";
print "Hello.... hello? hello world!\n"; 
close FILE;

但测试显示不然。

$ perl PrintTest.pl
Hello.... hello? hello world!

我们在这里写STDOUT,而不是FILE,这可能是最明智的结果,但似乎与上面引用的那条Perldoc相反。 也许我误解了“最后选择的输出句柄”是什么意思? 这是我能想到解释这个问题的唯一方法:-p

在此先感谢~ktm


I am confused by this bit of Perldoc:

If FILEHANDLE is omitted, prints to the last selected (see select) output handle. http://perldoc.perl.org/functions/print.html

It seems to say that a naked print statement, after writing to a filehandle, will print to that filehandle. I wrote a script to test this...

#!/usr/bin/perl

open (FILE, '>', 'PrintTest.txt') or die $!;
print FILE "Hello world!\n";
print "Hello.... hello? hello world!\n"; 
close FILE;

But the test shows otherwise.

$ perl PrintTest.pl
Hello.... hello? hello world!

We're writing to STDOUT here, not FILE, which is probably the most sensible result, but seems contrary to that line of Perldoc quoted above. Perhaps I am misunderstanding what "last selected output handle" means? That is the only way I can think to explain this :-p

Thanks in advance ~ ktm


原文:https://stackoverflow.com/questions/15780257
更新时间:2022-04-05 07:04

最满意答案

这里很棒的教程

想法是在第一次转换的持续时间内延迟第二次转换。

因此,如果你有1个转换,每个持续时间为1秒,则将第二个延迟1秒,第三个延迟2秒,因为我们必须等待第一个和第二个转换完成。 希望你能得到这个想法。

var canvas = d3.select('body')
						.append("svg")
						.attr("width",500)
						.attr("height",500);
		var addcircle = canvas.append("circle")
							.attr("cx",50)
							.attr("cy",50)
							.attr("r",25);		
		
		var circles = d3.select('circle');
		
		// first transition
		circles.transition().duration(1000)
				.attr("cx",250);
		
		// 2nd
		circles.transition().delay(1000)
				.duration(1000)
				.attr("cy",250)
		// 3rd
		circles.transition().delay(2000)
				.duration(1000)
				.attr("cx",50)
		// 4th
		circles.transition().delay(3000)
				.duration(1000)
				.attr("cy",50);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>


Excellent tutorial here

Idea is delay the second transition by the duration of first transition.

So if you have 3 transitions each of duration 1 sec then, delay the second by 1 sec and third by 2 sec, because we have to wait for both first and second transitions to complete. Hope you get the idea.

var canvas = d3.select('body')
						.append("svg")
						.attr("width",500)
						.attr("height",500);
		var addcircle = canvas.append("circle")
							.attr("cx",50)
							.attr("cy",50)
							.attr("r",25);		
		
		var circles = d3.select('circle');
		
		// first transition
		circles.transition().duration(1000)
				.attr("cx",250);
		
		// 2nd
		circles.transition().delay(1000)
				.duration(1000)
				.attr("cy",250)
		// 3rd
		circles.transition().delay(2000)
				.duration(1000)
				.attr("cx",50)
		// 4th
		circles.transition().delay(3000)
				.duration(1000)
				.attr("cy",50);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

相关问答

更多
  • 要在点之间绘制一条弧,为什么不使用弧指令(A)的路径。 我也尝试了很棒的ARC,但没有成功。 但是从这个讨论中找到了一个替代方案,下面给出了替代方案: path.attr("d", function(d) { var dx = d.target.x - d.source.x, dy = d.target.y - d.source.y, dr = Math.sqrt(dx * dx + dy * dy); return "M" + d.source.x + " ...
  • 部分回答我自己的问题,我觉得这里很愚蠢。 Y轴倒置了吗? 尝试交换范围! 有效。 一部分下来。 编辑以评论x轴问题。 这可能是翻译问题吗? 我看到绘制了y轴,但x轴的格式不同。 Partial answer to my own question, and I feel stupid here. Y-axis is upside down? Try swapping the range! It worked. One part down. Editing to comment on the x-axis is ...
  • 确保你通过实际的函数而不是函数的返回值,通过消除() : this.dragger = d3.drag() .on("drag", this.handleDrag) .on("end", this.endDrag); 对于您的其他问题,请使用(this as any).parentNode将其视为任何对象以避免打字稿问题。 Make sure you pass the actual function and not the return value of the function, ...
  • 我可以帮助修复你的过渡,但我不确定你试图“连锁”。 在链接示例中,Bostock将一行换成另一行(转换1),然后将该行与新域匹配(转换2)。 您似乎不想交换行,因此您适合新域,然后将行转换为它(转换1)但转换2是什么? 现在回答你更直接的问题,为什么你的过渡不起作用,这只是因为你永远不会更新你的数据。 在链接示例中,Bostock将两个数据集绑定到他的行,然后交换他在行函数中绘制的数据集。 但是,您只能绑定原始数据集。 快速修复是: function change() { ... //<-- get ...
  • 这里很棒的教程 想法是在第一次转换的持续时间内延迟第二次转换。 因此,如果你有1个转换,每个持续时间为1秒,则将第二个延迟1秒,第三个延迟2秒,因为我们必须等待第一个和第二个转换完成。 希望你能得到这个想法。 var canvas = d3.select('body') .append("svg") .attr("width",500) .attr("height",500); var addcircle = canvas.append("circle") ...
  • 我可以通过重新排列json数据来使其工作。 如果我使用x和y值的数组而不是x值的一个数组和y值的另一个数组,它会像我期望的那样绘制。 所以data看起来像这样: {"items":["itemID01","itemID12","itemID14","itemID15","itemID16"], "alpha":[{"x":"itemID03","y":0}, {"x":"itemID12","y":0}, {"x":"itemID14","y":0}, ...
  • 您可以通过根据每个节点的索引计算延迟来轻松完成此操作。 Mike Bostock 在这里有一个这样的实现的例子。 这是相关代码: var transition = svg.transition().duration(750), delay = function(d, i) { return i * 50; }; transition.selectAll(".bar") .delay(delay) .attr("x", function(d) { return x0(d.letter ...
  • 你可以用D3画出50万点吗? 当然,但不是SVG。 你将不得不使用canvas(这是一个包含基于画笔的选择的10,000点的简单例子: http : //bl.ocks.org/emeeks/306e64e0d687a4374bcd ),这意味着你不再需要单独的元素来分配点击处理程序至。 你将无法使用SVG渲染50万个点,因为正如你所提到的,所有这些DOM元素都会阻塞你的界面。 D3确实包括可用于群集的四叉树支持。 它在上面的示例中用于加速搜索,但您可以使用它在某些比例下嵌套元素。 最终,您的选择是: 1) ...
  • 对于我的问题,结果证明与d3.v3不兼容。 我使用的是d3.v3,但是nvd3的稳定版本使用d3.v2: https : //github.com/novus/nvd3/commit/7e9b8c013c4d8e8ad5775062c438c842bc112585 我通过包含nvd3 / lib中提供的d3.v2版本解决了这个问题: https : //github.com/novus/nvd3/blob/master/lib/d3.v2.min.js 在这里找到答案: https : //stackove ...
  • 一种方法是迭代所有点并检查x和y是否与点击的附近匹配。 当散点图点太多时,这肯定会很慢。{我认为在你的情况下,你在画布上制作散点图只是为了解决这个问题} 其他方法是使用四叉树。 首先,我做了一些随机10000点。 sampleData = d3.range(1000).map(function(d) { var datapoint = {}; datapoint.id = "Sample Node " + d; datapoint.x = Math.random() * 500; ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)