jQuery是否能够从服务器返回的X-JSON HTTP头中读取JSON数据?我一直在搜索jQuery文档,但我可以找到的所有示例都使用请求体中返回的JSON而不是标头.
我正在尝试创建一个"人"类型,每个人都有性别和名字.
data Sex = Sex Char deriving Show
male = Sex 'M'
female = Sex 'F'
data Name = Name [Char] deriving Show
data Person = Person {
Sex :: Sex,
Name :: Name
} deriving (Show)
Run Code Online (Sandbox Code Playgroud)
当我尝试在ghci中加载它时,我只是得到了无用的错误 parse error on input 'Sex'
我在这做错了什么?
我有以下Perl代码进行DBI调用:
my $artsql = q{ *** SNIP A BUNCH OF SQL ***
where a.article_id != ?
and at.type_name != 'List Element' -- don't get list children
and aw.flowstate = 'Published'
and a.visible_as_article = 1 }
. ( $filter ? q{and ch.channel_id = ?
and cat.category_id = ? }
: '' )
. q{order by a.publish_date desc
limit 5};
my @bind = ( $article );
push @bind, ( $channel_id, $category_id ) if $filter;
my $articles = $dbh->selectall_arrayref( $artsql, { Slice => …Run Code Online (Sandbox Code Playgroud) 关于我的正则表达式,我有一个问题/疑问.代码部分如下:
use strict;
my @list = ("1", "2", "123");
&chk(@list);
sub chk {
my @num = split (" ", "@_");
foreach my $chk (@num) {
chomp $chk;
if ($chk =~ m/\d{1,2}?/) {
print "$chk\n";
}
}
}
Run Code Online (Sandbox Code Playgroud)
在\d{4}将打印什么.在\d{3}将只打印123.但是,如果我改变\d{1,2}?它将打印所有.根据我到目前为止所读到的所有资料,我认为这{1,2}意味着:一位数但不超过两位.所以它应该只打印,1并且2正确吗?提取仅包含一到两位数字的项目需要什么?谢谢你的帮助.
好吧,我无法通过阅读Perl的文档来解决这个问题.我在看Apache的RHEL4 init脚本......这行代码有什么作用?
httpd=${HTTPD-/usr/sbin/httpd}
Run Code Online (Sandbox Code Playgroud)
为什么不httpd=/usr/sbin/httpd呢?所有额外的语法有什么用?
-Geoffrey Lee
我有这段代码读取traceroute的输出用于监视目的.
下面的这段代码工作正常.
for ($i = 0; $i < $sizeloc; $i++) {
for ($j = 0; $j < 1; $j++) {
if ($j==0) {
system("tracert " . $locations[$i][$j] . " > d:\\netmon\\"
. $locations[$i] [$j+1] );
}
}
}
Run Code Online (Sandbox Code Playgroud)
只要我调用这个子read_outputfile($ locations [$ i] [$ j + 1]); 在循环内部,出现问题.它只迭代一个对象然后我的程序结束.所以第一次调用read_outputfile时它会运行sub中的代码.只是,它不会返回循环.它结束了.
for ($i = 0; $i < $sizeloc; $i++) {
for ($j = 0; $j < 1; $j++) {
if ($j==0) {
system("tracert " . $locations[$i][$j] . " > d:\\netmon\\" .
$locations[$i][$j+1] );
read_outputfile($locations[$i][$j+1]); …Run Code Online (Sandbox Code Playgroud) 输入:命令行上的数字列表
输出:两个数字列表,一个输入数字大于零,另一个数字小于零(忽略零值数字)
这是我的代码
#!/usr/bin/perl
$i++ = 0;
$j++ = 0;
while ($number = <>)
{
if($number<0)
$first[$i++]=$number;
else
$second[$j++]=$number;
}
print "The numbers with value less than zero are\n";
foreach $number (@first)
print $number;
print "The numbers with value greater than zero are\n"
foreach $number(@second)
print $number;
Run Code Online (Sandbox Code Playgroud)
我得到以下愚蠢的错误,我无法纠正.错误是
divide.pl: 2: ++: not found
divide.pl: 3: ++: not found
divide.pl: 5: Syntax error: ")" unexpected
Run Code Online (Sandbox Code Playgroud)
有人可以帮我纠正这些错误吗?我是perl脚本的新手
我有以下子程序:
sub my_sub {
my $coderef = shift;
$coderef->();
}
sub coderef {
my $a = shift;
my $b = shift;
print $a+$b;
}
Run Code Online (Sandbox Code Playgroud)
并希望以my_sub(\coderef($a,$b))这种方式调用,即我想提供代码ref的参数,并在my_sub函数上运行它.在perl中可以做这样的事情吗?
在我的perl程序中需要
use strictures 1;
while(<>) {
chomp;
my($action, $v1, $v2) = map { s/XX/42/g; $_ } split /\s+/;
print "=$action=$v1=$v2=\n";
do_someting( $action, func1($v1), func2($v2) );
}
Run Code Online (Sandbox Code Playgroud)
问题是,当输入包含<3"字段"并且我想要确保所有不存在的字段都被定义并包含"DEFAULT".所以想要下一个:输入 - >分配输出到变量
"mk aXXb ac" -> "mk" "a42b" "ac"
"deXX ab" -> "de42" "ab" "DEFAULT"
Run Code Online (Sandbox Code Playgroud)
等等..
尝试了下一个,但不起作用.
my($action, $v1, $v2) = map { s/XX/42/g; $_ // "DEFAULT" } split /\s+/;
Run Code Online (Sandbox Code Playgroud)
这看起来比我误解了map和/或//操作员的工作方式.
我需要在我的路由器上输入scipt并查找代码并与之前记录的此IP信息进行比较,如果没有更改,则停止脚本.
我运行这个脚本 - $ perl~/test.pl
没有错误,但是没有创建文件my_ip.txt.
在原件脚本必须通过主机example.dyndns.org检查我的IP,但我的IP是灰色的.
所以我需要通过路由器来确定
#!/usr/bin/perl
use LWP::UserAgent;
my $routeraddress = `addr admin:Tavolzhansky@192.168.1.1/RST_conn_status.htm`;
if ($routeraddress =~ /var info_get_wanip="((\d+\.){3}(\d+))"/) {
my $ip = "$1.$2.$3.$4";
#?????????:
open (FILE,"my_ip.txt");
my @lines = <FILE>;
$old_ip = $lines[0]; #????????? IP ?? ?????
$old_ip =~ s/^\s+|\s+$//g; #trim
close(FILE);
if ($old_ip eq $ip) {
die "IP not changed"; # ??????? ?? ???????, ???? IP ?? ?????????
}
open (FILE,">my_ip.txt");
print FILE $ip; # ?????????? ? ???? ????? IP
close(FILE);
...... (this code is OK) …Run Code Online (Sandbox Code Playgroud)