C#中Console.Write("H")和Console.Write('H')之间的区别是什么?
$stuff = "d:/learning/perl/tmp.txt";
open STUFF, $stuff or die "Cannot open $stuff for read :$!";
while (<STUFF>) {
my($line) = $_; # Good practice to always strip the trailing
chomp($line);
my @values = split(' ', $line);
foreach my $val (@values) {
if ($val == 1){
print "1 found";
}
elsif ($val =~ /hello/){
print "hello found";
}
elsif ($val =~ /"/*"/){ # I don't know how to handle here.
print "/* found";
}
print "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
我的tmp.txt:
/* …Run Code Online (Sandbox Code Playgroud) 美好的一天.
我所知.XML文件中有一个根元素.
但是从XSD文件结构来看,获取根元素值并不容易.有没有办法做到这一点?
(我不想在我的项目中使用硬代码来查找XSD根元素值.我想找到"RootValueHere"的根元素
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="RootValueHere">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="DocumentInfo" minOccurs="1" maxOccurs="1" />
<xsd:element ref="Prerequisite" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- Element of DocumentInfo -->
<xsd:element name="DocumentInfo">
<xsd:complexType>
<xsd:attribute name="Name" type="xsd:string" />
<xsd:attribute name="Description" type="xsd:string" />
<xsd:attribute name="Creator" type="xsd:string" />
<xsd:attribute name="CreateTime" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- Element of Prerequisite -->
<xsd:element name="Prerequisite">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Type" type="Prerequisite.Type.type" minOccurs="1" maxOccurs="1" />
<xsd:element name="Miscellaneous" type="Prerequisite.Misc.type" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)
谢谢.
如何将子例程变量值传递到另一个子例程变量,我可以使用全局变量.
sub foo(){
my $myvar = "Hello";
}
sub foo1(){
my $myvar1 = $myvar; # how can I get the "Hello" from $myvar.
}
Run Code Online (Sandbox Code Playgroud)
我试图使用包和全局变量,但失败了.
Package Bar;
our $bar;
Run Code Online (Sandbox Code Playgroud)
谢谢.
我上周在WinXP上用Strawberry Perl替换了ActivePerl.
我发现我必须用命令运行我的Perl脚本perl myperl.pl; 否则我只需要myperl.pl在安装草莓之前运行.我怎么能myperl.pl像以前一样跑?
我检查了我的环境配置如下.
Run Code Online (Sandbox Code Playgroud)C:\> Path C:\Program Files\ActiveState Komodo Edit 5\;C:\Perl\site\bin;C:\Perl\bin;C:\Perl\bin\;C:\Program Files\CodeSynthesis XSD 3.2\bin\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Common Files\Thunder Network\KanKan \Codecs;C:\strawberry\c\bin;C:\strawberry\perl\bin`
安装成功后,Strawberry Perl路径已在Path值中列出.
我错过了什么?谢谢你的建议.
如何检查一行($ _ value)是Perl中的空行?还是另一个好方法来检查它而不是使用$ _?
我想这样编码
if($ _ eq'')#检查当前行是否为空行(没有任何字符){$ x = 0; }
我用下面的问题解决方案更新了一些代码.
我的test.txt用于解析:
constant fixup private GemAlarmFileName = <A "C:\\TMP\\ALARM.LOG">
vid = 0
name = ""
units = ""
constant fixup private GemConfigAlarms = <U1 0> /* my Comment */
vid = 1
name = "CONFIGALARMS"
units = ""
min = <U1 0>
max = <U1 2>
default = <U1 0>
Run Code Online (Sandbox Code Playgroud)
我的代码如下.
这就是为什么我需要最初设置$ x = 0.我不确定它是否是正常的解决方案.
sub ConstantParseAndPrint
{
if (/^$/) // SOLUTION!
{
$x = 0; …Run Code Online (Sandbox Code Playgroud) 我刚问了一个关于如何在Perl中检查当前行是否为空的问题.
这适用于当前行,但如何检查下一行是否为空?
要解析的文本文件:(我需要解析文本文件并创建一个新的XML文件)
constant fixup GemEstabCommDelay = <U2 20>
vid = 6
name = "ESTABLISHCOMMUNICATIONSTIMEOUT"
units = "s"
min = <U2 0>
max = <U2 1800>
default = <U2 20>
constant fixup private GemConstantFileName = <A "C:\\TMP\\CONST.LOG">
vid = 4
name = "" units = ""
constant fixup private GemAlarmFileName = <A "C:\\TMP\\ALARM.LOG">
vid = 0
name = ""
units = ""
Run Code Online (Sandbox Code Playgroud)
我想要下面的输出.
<EquipmentConstants>
<ECID logicalName="GemEstabCommDelay " valueType="U2" value="20" vid="6" name="ESTABLISHCOMMUNICATIONSTIMEOUT" units="s" min="0" max="1800" default="20"></ECID>
<ECID …Run Code Online (Sandbox Code Playgroud) 我宣布了字典obj.
Dictionary<string, string> aDict = new Dictionary<string, string>();
aDict .Add("IP", "Host");
Run Code Online (Sandbox Code Playgroud)
我记得,
表达式aDict[IP]可以返回值(Host).
现在,如果我走向相反的方向.
如何从价值中获取关键?aDict[Host]?
字典是否是C#中的单行道,只能从Key运行到Value?谢谢.
如果我不需要命中block2,如何返回值.
它有意义吗?我想我不应该使用multi return,但我无法替换它break.有没有封闭循环外面中断或继续.
public EnResult MyFun()
{
bool bRet = default;
// block1 . higher priority than block2.
if (true)
{
// if bRet = true_1, not need hit block2. That's why I want to nested my code with multi *return*
return bRet = true_1;
}
else
{
// do nothing
}
// block2
if (true)
{
return bRet = true_2;
}
else
{
// do nothing
}
return bRet;
}
public enum EnResult
{ …Run Code Online (Sandbox Code Playgroud) float f1 = 123.125;
int i1 = -150;
f1 = i1; // integer to floating conversion
printf("%i assigned to an float produces %f\n", i1, f1);
Run Code Online (Sandbox Code Playgroud)
输出:
-150 assigned to an float produces -150.000000
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么结果000000后面有6个零().而不是7或8或一些数字?
perl ×5
c# ×4
regex ×3
.net ×1
c ×1
command-line ×1
console ×1
dictionary ×1
printf ×1
return ×1
subroutine ×1
two-way ×1
types ×1
xml ×1
xsd ×1