我打算跳过包含"MaterialiseU4()"起始行的块内容和read_block下面的subroutin().但失败了.
# Read a constant definition block from a file handle.
# void return when there is no data left in the file.
# Otherwise return an array ref containing lines to in the block.
sub read_block {
my $fh = shift;
my @lines;
my $block_started = 0;
while( my $line = <$fh> ) {
# how to correct my code below? I don't need the 2nd block content.
$block_started++ if ( ($line =~ /^(status)/) && (index($line, "MaterializeU4") …Run Code Online (Sandbox Code Playgroud) 我的data.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd country="UK">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>10.0</price>
</cd>
<cd country="CHN">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.99</price>
</cd>
<cd country="USA">
<title>Hello</title>
<artist>Say Hello</artist>
<price>0001</price>
</cd>
</catalog>
Run Code Online (Sandbox Code Playgroud)
我的test.pl
#!/usr/bin/perl
# use module
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
# read XML file
$data = $xml->XMLin("data.xml");
# access XML data
print "$data->{cd}->{country}\n";
print "$data->{cd}->{artist}\n";
print "$data->{cd}->{price}\n";
print "$data->{cd}->{title}\n";
Run Code Online (Sandbox Code Playgroud)
输出:
Not a HASH reference at D:\learning\perl\t1.pl line 16.
Run Code Online (Sandbox Code Playgroud)
评论:我用Google搜索并找到了文章(处理单个xml记录). http://www.go4expert.com/forums/showthread.php?t=812 我测试了文章代码,它在我的笔记本电脑上运行良好.
然后我创建了上面的练习代码以尝试访问多个记录.但失败了.我该如何解决?谢谢.
当我声明int weight然后输入一个double值时165.1,2nd cin >> height;不起作用,并且没有任何错误消息.你能告诉我为什么吗?
使用VS2010控制台应用程序.
#include <iostream>
using namespace std;
const double lbs_to_kg = 2.2046, inches_to_meter = 39.370;
int main()
{
int weight, height;
double kilograms, meters;
cout << "\nEnter weight in pounds: ";
cin >> weight;
kilograms = weight / lbs_to_kg;
cout << "\nEnter height in inches: ";
cin >> height;
meters = height / inches_to_meter;
cout << "\nYour BMI is approximately "
<< "\nbody fat ratio is "
<< kilograms / (meters …Run Code Online (Sandbox Code Playgroud) 如果我宣布了 bool isTrue = false; // init it to false
我可以从a获得价值 string strVal = T; // I assumed it is the TRUE value
我听说在C#中比较字符串并不是一个好的代码风格
if (isTrue.tostring() == strVal) {}.
有一段时间,我将字符串变量转换为枚举然后我可以比较它更方便.
有什么好方法吗?
是否有任何简单的方法在int变量之前连接'0'.
喜欢:
int i = 2;
// produce
i = someMethod(i);
// output:
i = 02
Run Code Online (Sandbox Code Playgroud) 当我解析包含数千行的复杂文件时,我遇到了问题.
我已经像今天一样实现了我的Perl脚本.
my ($head, $tail) = split /=/, $line;
Run Code Online (Sandbox Code Playgroud)
我的几乎所有源文件$line样式如下:
constant normalLines = <type value> /* hello world */
Run Code Online (Sandbox Code Playgroud)
我可以得到输出 $tail = /* hello world */
今天我在解析这样的行时发现了一个错误(行中有两个=)
constant specialLine = <type value> /* hello = world */
Run Code Online (Sandbox Code Playgroud)
但现在输出是 $tail = /* hello
如何split()在上面的代码中修复仍然使用的bug ?我仍然想要输出$tail = /* hello = world */
你能告诉我/*=NULL*/下面的意思吗?
CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
: CDialog(CCycleTimes::IDD, pParent)
{
// Some code here
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我复制了同一条线.
成功评论为下面的syte
// CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
// : CDialog(CCycleTimes::IDD, pParent)
Run Code Online (Sandbox Code Playgroud)
否则,评论失败为下面的样式.
/*
CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
: CDialog(CCycleTimes::IDD, pParent)
*/
Run Code Online (Sandbox Code Playgroud)
为什么评论操作失败了?
当我在Windows XP上的ActivePerl 5.8上运行此程序时,出现语法错误:
#!C:\Perl\bin\perl.exe
use strict; # enabled
use warnings;
(my $rocks[0], my $rocks[1]) = qw/Hello World/; # Syntax error near '$rocks['
my $rocks[2] = 'Tom'; # Syntax error near '$rocks['
my $rocks[3] = 'Cat'; # Syntax error near '$rocks['
print $rocks[0];
print $rocks[1];
print $rocks[2];
print $rocks[3];
Run Code Online (Sandbox Code Playgroud)
当我@在数组名称之前使用()时rocks,它运行良好.我使用时如何修复上述错误$?谢谢.
my @rocks = qw{Hello World Tom Cat}; # worked well.
Run Code Online (Sandbox Code Playgroud) 如何改进我的Perl正则表达式以处理__DATA__以下问题?
my ($type, $value) =~ /<(\w+)\s+(.*?)\(\)>/;
__DATA__
<dynamic DynamicVar>
<dynamic DynamicVar > # not need attache the blackspace to $value when return
<dynamic DynamicFun()>
<dynamic DynamicFun() > # not need attache the blackspace to $value when return
Run Code Online (Sandbox Code Playgroud)
我想返回$type,并$value为这种格式<$type $value>.
当我们用C或C++谈论Bit Operation时.位是从bit0还是bit1开始的?哪一个更有意义?据我所知,有点可以采用两个值中的任何一个:1或0.