在vim中,我喜欢使用相对的亚麻布来查看我需要拉出,删除等等多少行.
但是,当使用相对的亚麻布时,当前行是0,这意味着,如果我想要直到数字3的行,我必须输入4yy,这有点违反直觉并且让我放慢速度.
有没有办法显示以1而不是0开头的相关亚麻布?
我在搞清楚如何引用外部模块文件中的子例程时遇到了一些麻烦.现在,我这样做:
外部文件
package settingsGeneral;
sub printScreen {
print $_[0];
}
Run Code Online (Sandbox Code Playgroud)
主要
use settingsGeneral;
my $printScreen = settingsGeneral::printScreen;
&$printScreen("test");
Run Code Online (Sandbox Code Playgroud)
但这导致错误:不能使用字符串("1")作为子程序ref,而"strict refs"在使用中
我一直在尝试向外部服务器发出ajax请求.到目前为止,我已经了解到,由于安全原因,我需要使用getJSON来执行此操作?
现在,我似乎无法对外部页面进行简单的调用.我试图尽可能地简化它,但它仍然无法正常工作.我有2个文件,test.html和test.php
我的test.html这样打电话给localhost进行测试:
$.getJSON("http://localhost/OutVoice/services/test.php", function(json){
alert("JSON Data: " + json);
});
Run Code Online (Sandbox Code Playgroud)
我希望我的test.php返回一个简单的'测试':
$results = "test";
echo json_encode($results);
Run Code Online (Sandbox Code Playgroud)
我可能会犯一些令人难以置信的菜鸟错误,但我似乎无法弄明白.此外,如果这有效,我怎样才能将数据发送到我的test.php页面,就像test.php?id = 15一样?
test.html页面调用localhost上的test.php页面,同一目录我没有收到任何错误,只是没有警告..
我在PHP中有一个多维数组,如下所示:
$array = array(
"Part1" => array(
"Subpart1" => array(0, 1),
"Subpart2" => array(1, 0)
),
"Part2" => array(0),
"Part3" => array(0, 1, 0)
);
Run Code Online (Sandbox Code Playgroud)
现在我想将这个数组存储在一个MySQL表中,并在另一个PHP页面上再次检索它.
我一直在尝试使用serialize()和unserialize()
$array= serialize($array);
Run Code Online (Sandbox Code Playgroud)
然后在另一页上
$array= $row['Array'];
$array2 = array();
$array2 = unserialize($array);
Run Code Online (Sandbox Code Playgroud)
但我似乎做了错事,在开始的时候我有一个var_dump的布尔(假的),现在我得到var_dump的NULL.
我有一个Perl脚本,可以启动2个线程,每个处理器一个.我需要它等待一个线程结束,如果一个线程结束,则生成一个新线程.似乎join方法阻塞了程序的其余部分,因此第二个线程不能结束,直到第一个线程完成的所有操作都失败了.
我试过这个is_joinable方法,但似乎也没办法.
这是我的一些代码:
use threads;
use threads::shared;
@file_list = @ARGV; #Our file list
$nofiles = $#file_list + 1; #Real number of files
$currfile = 1; #Current number of file to process
my %MSG : shared; #shared hash
$thr0 = threads->new(\&process, shift(@file_list));
$currfile++;
$thr1 = threads->new(\&process, shift(@file_list));
$currfile++;
while(1){
if ($thr0->is_joinable()) {
$thr0->join;
#check if there are files left to process
if($currfile <= $nofiles){
$thr0 = threads->new(\&process, shift(@file_list));
$currfile++;
}
}
if ($thr1->is_joinable()) {
$thr1->join;
#check if there are …Run Code Online (Sandbox Code Playgroud) 我正在玩错误处理并遇到一些问题.我使用DBI模块连接数据库.
我通过使用我调用错误的子例程来执行自己的错误处理.
我可以捕获我自己的死并处理它们就好了但是当我的数据库连接失败时,DBI模块显然打印出它自己的死:
DBI connect(...)失败:ORA-12154:TNS:无法解析指定的连接标识符(DBD ERROR:OCIServerAttach)...
我怎么去抓这个?
我试过这样使用$SIG{__DIE__}:
local $SIG{__DIE__} = sub {
my $e = shift;
print "Error: " .$e;
};
Run Code Online (Sandbox Code Playgroud)
这是在我的主文件的底部,在这个文件中我也调用了我自己的模块中可用的connect子例程.我也尝试将这段代码放在我的模块的底部,但它仍然打印出没有的错误
错误:
在它面前.
好的,所以我要做的就是在我的命令行中输出一个完整的百分比,现在,我希望这只是"更新"屏幕上显示的数字.所以不知何故回到行的开头并改变它.
例如,windows relog.exe命令行实用程序(可以将.blg文件转换为.csv文件)执行此操作.如果您运行它,它将显示完成百分比.
现在这可能是用C++编写的.我不知道perl中是否可能这样做?
我试图在多个线程上共享多维哈希.这个哈希包含2个连接的密钥对,我需要知道它们是否已经连接,如果不是,我需要连接它们,如果没有,就没有必要去数据库了.
use threads;
use threads::shared;
my %FLUobject2param : shared = ();
#Start a new thread for every available processor
for (my $i=0;$i<$PROCESSORS;$i++) {
threads->new(\&handlethread);
}
#Catch if these threads end
foreach my $onthr (threads->list()) {
$onthr->join();
}
sub handlethread{
...
if(not defined $FLUobject2param{$objectID}{$paramID}){
$dbh->getObject2Param($objectID,$paramID);
$FLUobject2param{$objectID}{$paramID} = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我不断收到错误Invalid value for shared scalar就行了
if(not defined $FLUobject2param{$objectID}{$paramID}){
这显然与perl的线程:: shared共享只允许您共享单个级别的共享结构.
我怎样才能检查这个组合是否已用于多个线程?
我在使用Blogger API for PHP工作时遇到了问题.
我需要的是能够在我的bloggeraccount上发布一个新的博客帖子.我正在使用的代码来自Google API页面:http: //code.google.com/intl/nl/apis/blogger/docs/1.0/developers_guide_php.html
这是我的代码:
<?
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$user = 'name@example.com';
$pass = 'password';
$service = 'blogger';
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null,
Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$gdClient = new Zend_Gdata($client);
$blogID = '7973737751295446679';
function createPublishedPost($title='Hello, world!', $content='I am blogging on the internet.')
{
$uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
$entry = $gdClient->newEntry();
$entry->title = $gdClient->newTitle($title);
$entry->content = $gdClient->newContent($content);
$entry->content->setType('text');
$createdPost = $gdClient->insertEntry($entry, $uri);
$idText = split('-', $createdPost->id->text);
$newPostID = …Run Code Online (Sandbox Code Playgroud) 我有一个问题,我似乎无法弄明白,我希望你们能帮助我.
问题发生在:
例:
主文件
use strict;
use warnings;
# signal handling
$SIG{__DIE__} = sub {
my $error = @_;
chomp $error;
print "die: $error\n";
};
require mod;
mod->get_stat();
Run Code Online (Sandbox Code Playgroud)
模
package mod;
use strict;
use warnings;
use File::stat;
sub get_stat {
my $file_path = "test.txt";
my $file_size = stat($file_path)->size;
print $file_size;
}
1;
Run Code Online (Sandbox Code Playgroud)
这将导致以下输出:
die: 1
die: 1
die: 1
die: 1
die: 1
4
Run Code Online (Sandbox Code Playgroud)
现在,如果我删除我的自定义错误处理或者如果我使用 mod而不是require将不会显示模具.
有趣的是它确实产生了一个结果(test.txt是4个字节),这意味着stat正在按预期工作. …
如何从javascript中的对象调用函数,例如在jquery中调用myDiv.html()来获取该div的html.
所以我想要的是这个工作:
function bar(){
return this.html();
}
alert($('#foo').bar());
Run Code Online (Sandbox Code Playgroud)
这是一个简化的例子,所以请不要说:只做$('#foo').html():)