Perl的打印功能:打印到最后的文件句柄?(Perl's print function: print to last filehandle?)
我对Perldoc的这一点感到困惑:
如果省略FILEHANDLE,则打印到最后选择的(参见select)输出句柄。 http://perldoc.perl.org/functions/print.html
似乎在写入文件句柄后,一个裸露的
#!/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
#!/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
最满意答案
这里很棒的教程
想法是在第一次转换的持续时间内延迟第二次转换。
因此,如果你有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 + " ...
-
使用D3.js显示图表(Displaying charts with D3.js)[2023-07-29]
部分回答我自己的问题,我觉得这里很愚蠢。 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 ... -
以角度4实现d3.js(Implementing d3.js in angular 4)[2023-10-12]
确保你通过实际的函数而不是函数的返回值,通过消除() : 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 ...
-
javascript d3.js - 散点图上点的多次转换(javascript d3.js - Multiple transitions of points on a scatter plot)[2023-08-15]
这里很棒的教程 想法是在第一次转换的持续时间内延迟第二次转换。 因此,如果你有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.js - 未捕获的TypeError:无法读取未定义的属性“数据”(d3.js - Uncaught TypeError: Cannot read property 'data' of undefined)[2023-01-26]
对于我的问题,结果证明与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; ...