我试图学习Devel::Declare,以尝试重新实现像PDL::NiceSlice没有源过滤器的东西.当我注意到它正在从我的脚本中删除下一行时,我正在某个地方.为了说明我已经做了这个最小的例子,其中一个人可以使用comment关键字从代码中删除整行,允许编译,即使该行上有大量的字.
#Comment.pm
package Comment;
use strict;
use warnings;
use Devel::Declare ();
sub import {
my $class = shift;
my $caller = caller;
Devel::Declare->setup_for(
$caller,
{ comment => { const => \&parser } }
);
no strict 'refs';
*{$caller.'::comment'} = sub {};
}
sub parser {
#my $linestr = Devel::Declare::get_linestr;
#print $linestr;
Devel::Declare::set_linestr("");
}
1
Run Code Online (Sandbox Code Playgroud)
和
#!/usr/bin/env perl
#test.pl
use strict;
use warnings;
use Comment;
comment stuff;
print "Print 1\n";
print "Print 2\n";
Run Code Online (Sandbox Code Playgroud)
只收益率
Print …Run Code Online (Sandbox Code Playgroud) 任何人都可以查看我的陈述......
DECLARE @tblName varchar(MAX),
@strSQL varchar(MAX)
SET @tblName ='SELECT DISTINCT o.name as TableName
FROM sysobjects o
JOIN sysindexes x on o.id = x.id
WHERE o.name LIKE ''%empty%'''
SET @strSQL = 'INSERT INTO @tblName VALUES(''trylng'', ''1'')'
EXEC (@strSQL)
Run Code Online (Sandbox Code Playgroud)
我的错误是......
消息1087,级别15,状态2,行1
必须声明表变量"@tblName".
我想要做的是变量得到表名@tblName,并插入一些数据@strSQL变量
例如......结果@tblName是CustomerInfo
然后在@strSQL我将使用结果@tblName作为我的插入命令中的表名.
所以@strSQL变量将是;
INSERT INTO CustomerInfo VALUES(......)
Run Code Online (Sandbox Code Playgroud) 我正在阅读使用dojo的声明进行类创建的语法.描述令人困惑:
The declare function is defined in the dojo/_base/declare module. declare accepts three arguments: className, superClass, and properties.
ClassName
The className argument represents the name of the class, including the namespace, to be created. Named classes are placed within the global scope. The className can also represent the inheritance chain via the namespace.
Named Class
// Create a new class named "mynamespace.MyClass"
declare("mynamespace.MyClass", null, {
// Custom properties and methods here
});
A class named mynamespace.MyClass is now …Run Code Online (Sandbox Code Playgroud) 我的bash脚本有问题.我做的是分配这样的变量.
for ((i=START;i<=END;i++)
declare var$i=$(something)
done
Run Code Online (Sandbox Code Playgroud)
它有效,但现在我遇到了å,ä,ö等芬兰字符的问题.宣称的是这样的
bash:declare 'wörd' not a valid identifier
Run Code Online (Sandbox Code Playgroud)
虽然我这样做但效果很好
declare var2=$(sömething)
Run Code Online (Sandbox Code Playgroud)
我可以用sed转换字符,但最好还是像往常一样,所以这是最后的解决方案.所以我想知道如何分配变量
var$i
Run Code Online (Sandbox Code Playgroud)
与芬兰人物.wörd这个词是我命令'something'输出的一部分.当有两个或更多单词时,只有包含字符ö,ä等的单词不会分配给变量,所以如果命令的输出是"某些东西",则唯一显示的是有回声是一回事.
在 C 语言中,不能在“case”语句中声明任何变量。
switch ( i ){
case 1:
int a = 1; //error!
break;
}
Run Code Online (Sandbox Code Playgroud)
但是,当您与花括号一起使用时,您可以。
switch ( i ){
case 1:
{// create another scope.
int a = 1; //this is OK.
}
break;
}
Run Code Online (Sandbox Code Playgroud)
在 Javascript 情况下,我可以在 case 语句中直接使用 var 吗?
switch ( i ){
case 1:
var a = 1
break
}
Run Code Online (Sandbox Code Playgroud)
似乎没有错误,但我不确定这在语法上是否正确。
# declare score as integer
score = int
# declare rating as character
rating = chr
# write "Enter score: "
# input score
score = input("Enter score: ")
# if score == 10 Then
# set rating = "A"
# endif
if score == 10:
rating = "A"
print(rating)
Run Code Online (Sandbox Code Playgroud)
当我执行此代码并输入“10”时,我在 shell 中得到了内置函数 chr。我希望它根据分数打印 A 或其他字符。例如,如果输入分数是 8 或 9,则必须读取 B。但是,我试图首先通过第一步。我是编程新手,如果我能指出正确的方向,那将大有帮助。
我正在创建一个用于不同项目的打字稿库。我想要的是仅向外部发布类函数的一个子集,并在我的库内部使用其他函数。
在示例中:
/* Person.ts */
export class Person{
getName(){
.....
return name;
}
getInfos(){
}
}
/* People.ts */
export class People{
...
setName(){
let p = new Person();
...
let n = p.getName();
....
}
}
Run Code Online (Sandbox Code Playgroud)
我希望我的库公开 Person getInfos() 和 People setName(),但我希望 Person getName 只能在内部访问。也许我必须创建一个 Person.d.ts ,只向外部用户公开一种方法,但我不明白如何做。
谢谢
问题
declare -p获取有效Bash关联数组的结果,其中键包含方括号会导致错误的数组下标错误.
测试程序
做:
$ declare -A array
$ key='var[0]'
$ array["$key"]=37
$ echo ${array["$key"]}
37
$ declare -p array > def.sh
$ cat def.sh
declare -A array='(["var[0]"]="37" )'
$ . def.sh
bash: [var[0]]=37: bad array subscript
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,请注意:
var[0]declare -p我能够将此定义保存到文件:def.shdef.sh会发出错误.我的环境
解决方法
如果不是declare -p array > def.sh我这样做:
{
echo 'declare -A array'
for Key in "${!array[@]}"; …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关如何声明 FileSystemObjects 对象的信息,发现了令人困惑的信息。是因为声明方式不同吗?
我向您展示了我发现的一些声明和定义 FileSystemOjbect 对象的方法:
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
Dim FSO As New FileSystemObject
Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
声明 FileSystemObject 对象的正确方法是什么?
在这段代码中,example1让example2我感到困惑:
type F1 = (a: string, b:string) => void;
type F2 = (a: number, b:number) => void;
// re: example 1 and 2:
// After the =, | means "or" and & means "and"
// Before the =, & means "or" and | means "and"
const example1: F1 & F2 = (a: string | number, b: string | number) => {}
example1("Hello", "World")
example1(1, 2)
// example1("Hello", 2) // Error! number is not assignable to …Run Code Online (Sandbox Code Playgroud)