- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 perl 很陌生,所以我确信我在这里的困惑仅仅是由于不理解 perl 语法以及它如何处理裸词。不过,我无法在网上找到我的问题的好答案。
我有我正在重构的代码,它曾经看起来像这样
@month_dirs = <$log_directory/*>;
@month_dirs = <$conf->log_directory()."/*">
$month_directory_command = $conf->log_directory()."/*";
@month_dirs = <$month_directory_command>;
$month_directory_command = $conf->log_directory();
@month_dirs = <$month_directory_command/*>;
$bare_word = $conf->log_directory()/*
$month_directory_command = $conf->log_directory();
$bare_word = $month_directory_command/*;
@month_dirs = <$bare_word>;
最佳答案
您误认为钻石运算符 <>
仅适用于裸词:
$ perl -E'say for <"/*">'
/bin
/boot
/dev
...
(事实上,一个裸词只是一个没有符号的标识符,并且被
use strict 'subs';
禁止,所以你的例子都没有真正符合条件。)
@month_dirs = <$log_directory/*>;
之所以有效,是因为在
<>
内部完成了一定程度的双引号内插。 , 和标量变量,如
$log_directory
被插值。
@month_dirs = glob("$log_directory/*");
@month_dirs = <$conf->log_directory()."/*">
失败,因为
>
在
$conf->log_directory()
过早关闭菱形运算符,使解析器感到困惑。
<$conf->
(调用
glob
)然后
log_directory()."/*">
这是一个语法错误。
$month_directory_command = $conf->log_directory()."/*";
@month_dirs = <$month_directory_command>;
失败是因为
<$month_directory_command>
相当于
readline($month_directory_command)
而不是
glob("$month_directory_command")
来自
perldoc perlop
:
If what the angle brackets contain is a simple scalar variable (for example,
$foo
), then that variable contains the name of the filehandle to input from, or its typeglob, or a reference to the same.[...]
If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context. This distinction is determined on syntactic grounds alone. That means
<$x>
is always areadline()
from an indirect handle, but<$hash{key}>
is always aglob()
.
$month_directory_command
) 中读取。
use warnings 'all';
打开警告会提醒你这一点:
readline() on unopened filehandle at foo line 6.
$bare_word = $conf->log_directory()/*;
失败,因为您试图将方法调用的结果与未加引号的字符串连接起来;要连接字符串,您必须将它们插入双引号字符串,或使用连接运算符。
$bare_word = $conf->log_directory() . "/*";
@month_dirs = <"$bare_word">;
(尽管
$bare_word
根本不是一个裸词,它是一个标量变量。)
@month_dirs = <$bare_word>;
(不带引号)将被解释为
readline
,而不是
glob
,如
perlop
中所述多于。
glob
可能不会那么困惑。运营商直接:
@month_dirs = glob( $conf->log_directory() . "/*" );
关于perl - 菱形算子在解析和裸词中的语法混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34420975/
我关注了这个:How can I enable Flutter/Dart language experiments? 但是,传播运算符仍然对我不起作用。 最佳答案 您需要从终端运行 flutter u
在各种场合我都希望收到一个 Rx Replay 缓冲传入通知的运算符,在第一次订阅时同步重放其缓冲区,然后停止缓冲。此轻量级 Replay运营商应该只能为一个用户提供服务。可以找到此类运算符的一个用例
var items = []; var index = 0; var value = items[index]; // returns invalid value error, understood!
我想在文本中找到笔划的方向。 Sobel 算子如何用于此目的? 这张图显示的是dp,也就是梯度方向。我想知道如何应用 Sobel 运算符找到要选择的像素,从 p 到 q,沿着路径 sp,到找到边缘上的
我正在尝试在水平和垂直方向上实现 sobel 运算符。但不知何故我得到了反向输出。我在下面附上的代码。对于水平蒙版 char mask [3][3]= {{-1,-2,-1},{0,0,0},{1,
我在使用 Sobel 算子进行边缘检测时遇到问题:它会产生太多假边缘,效果如下图所示。我正在使用 3x3 sobel 运算符 - 首先提取垂直然后水平,最终输出是每个滤波器输出的幅度。合成图像的边
我很难理解 &^ and &^= operators 是什么在围棋中的意思。我无法在文档(说明操作符有点清晰,但对我帮助不大)或试验中找到答案。 特别是,我想知道 Python 中是否有等效项。 最佳
我目前正在从包含体素的 MRI 数据量中去除不均匀性。我想在这些体积上应用 sobel 算子来找到梯度。我熟悉 2d sobel mask 和 2d 图像的邻域。 索贝尔面具: 1 2 1 0 0 0
Img 是我输入的 RGB 图像 import cv2 import numpy as np img = cv2.imread("Lenna.png") black = cv2.cvtColor(im
我正在用 C#.net 做人脸检测项目,在某些情况下,我从 sobel 获得了更好的结果,而在其他一些情况下,我从 canny 获得了更好的结果。但实际上哪个更好? 最佳答案 Canny 建立在 So
我是一名优秀的程序员,十分优秀!