我正在开发一个小脚本,但使用几个curl 和while 循环有点搞砸了。
我想在其中一个 URL 向我提供信息时停止处理curl。注意:我有多个卷曲请求。
所以我的理念是,
我有几个 URL,我必须对其进行处理并从中获取信息。如果在特定 URL 上找到信息,它将给我一个字符串。如果找不到信息,它就不会给我任何价值。所以我大约有近 10 个 URL 需要处理。在所有情况下,任何一个 URL 都会向我提供信息,因此其余 URL 将不会产生任何价值。由于要处理大量 URL,因此延迟是一个问题。因此,假设在下面的示例代码中,如果以 value2.php 结尾的 url 给了我一个结果,那么我立即想停止处理其他 URL。因为我已经得到了结果,没有必要运行其他卷曲。最后我必须打印结果。
另外,我遇到的情况是,所有 URL 都不会产生任何结果,如果有人向我展示如何处理该问题,那就太好了。
我的示例代码。
<?php
///functions here
do {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"example[dot]com/value1.php?process=$param");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$combined = curl_exec ($ch);
curl_close ($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"example[dot]com/value2.php?process=$param");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$combined = curl_exec ($ch);
curl_close ($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"example[dot]com/value3.php?process=$param");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$combined = curl_exec ($ch);
curl_close ($ch);
$ch = curl_init();
curl_setopt($ch, …Run Code Online (Sandbox Code Playgroud) 我正在数据框上应用 na.approx,如果 NA 恰好位于数据库的第一行或最后一行,则该方法将不起作用。
如何编写执行以下操作的函数:“当数据帧第一行的任何值为 NA 时,删除第一行”
数据框示例:
x1=x2=c(1,2,3,4,5,6,7,8,9,10,11,12)
x3=x4=c(NA,NA,3,4,5,6,NA,NA,NA,NA,11,12)
df=data.frame(x1,x2,x3,x4)
Run Code Online (Sandbox Code Playgroud)
此示例数据框的结果应如下所示:
result=df[-1:-2,]
Run Code Online (Sandbox Code Playgroud)
我当前的尝试看起来都类似于:
replace_na=function(df){
while(anyNA(df[1,])=TRUE){
df=df[-1,],
return(df)
}
#this is where I would apply the na.approx function to the data frame
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,谢谢!
我刚刚开始学习 shell,对 read line(variable) 命令如何读取文件感到困惑
done < filename.
Run Code Online (Sandbox Code Playgroud)
代码 :
while read LINE; do
echo "This is a downvote"
done < inputfile
Run Code Online (Sandbox Code Playgroud)
我的假设是,当 while 运行行变量为空时,它应该为 false,而 while 循环退出,但事实并非如此。是否读取循环中的文件检查,并且我知道输入重定向命令已传递到文件。有人可以解释一下它是如何工作的吗?
我有一个名为“事件”的自定义帖子类型。所有这些事件页面都有一个ACF 日期字段来输入事件开始日期。在事件存档页面中,我想将这些事件分为两组。
所以即将推出的活动将是这样的:
<?php
$today = date('Ymd');
$args = array(
'post_type' => 'events',
'nopaging' => true,
'orderby' => 'meta_value_num',
'meta_key' => 'event_start_date', //ACF date field
);
$upcoming_events = new WP_Query( $args );
if ( $upcoming_events->have_posts() ) :
?>
<h2>Upcoming Events</h2>
<ul>
<?php while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post(); ?>
<li>
Title: <?php the_title(); ?><br>
Date: <?php echo get_field('event_start_date'); ?>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
我知道有 meta_query …
list1 = ["apple", "pear", "", "strawberry", "orange", "grapes", "", "watermelon"]
list2 = []
x = 0
while x < len(list1):
if len(list1[x]) > 0:
list2.append(list1[x])
print(list2)
Run Code Online (Sandbox Code Playgroud)
我尝试运行这段代码,但似乎不起作用。我应该如何不使用列表理解或其他方法来修改此代码?
while (<>) { $file .= $_};该代码由于某种原因挂起,或者在查询时不再继续执行。这是为什么?
一旦我用输入的文本启动代码,就不会发生比它输出的更多的事情task1,然后它就会挂起。
代码:
#!/usr/bin/perl -w
use strict;
use JSON;
my $json = JSON->new->allow_nonref;
my $file = "";
print('task1');
while (<>) { $file .= $_ };
print('task2');
my $json_output = $json->decode( $file );
my ($c, $i, $cstr, $istr);
foreach my $cert (@$json_output) {
print('task3');
$i = $json_output->{i};
$c = $json_output->{c};
$istr = join("", map { sprintf("%02x",$_) } @$i);
$cstr = pack("C*", @$c);
open(F, ">$istr.der"); print F $cstr; close(F);
print('done.');
}
Run Code Online (Sandbox Code Playgroud)
输出:
task1
Run Code Online (Sandbox Code Playgroud) 考虑证明以下 while 循环的正确性,即我想表明,给定循环条件开始时,它最终将终止并导致最终断言为真。
int x = 0;
while(x>=0 && x<10){
x = x + 1;
}
assert x==10;
Run Code Online (Sandbox Code Playgroud)
在不使用循环展开的情况下,用于检查正确性的 SMT-LIB 的正确翻译是什么?
所以我昨天刚开始 C++,我有相当多的 java 经验,所以这就是原因,我尝试运行这段代码,由于某种原因 while 循环没有循环,我尝试将 if break 语句从 更改ask==false为ask=false,这最终会导致无限循环,甚至不接受用户输入。
这是代码:
#include <iostream>
#include <math.h>
using namespace std;
int main(){
double raduis;
const double pi = 3.14;
bool ask;
while(true){
cout << "Enter the raduis of the circle:"<< endl;
cin >> raduis;
double circ = 2*pi*raduis;
double area = pi*pow(raduis,2);
cout << "The Circumference of the circle is: "<< circ <<endl;
cout << "The Area of the circle is: "<< area<<endl;
cout <<"Would you like to …Run Code Online (Sandbox Code Playgroud) 问候大家,
我有这个表(没有 Res_Problem):
| ID | 问题 | X | 影响 | 概率 | 解决问题 |
|---|---|---|---|---|---|
| 识别号1 | 12 | 数据中心1 | 1 | 2 | (12-2)=10 |
| 识别号1 | 12 | 数据中心2 | 2 | 2 | (10-4)=6 停止 |
| 识别号1 | 12 | 数据中心3 | 1 | 0 | 无循环 |
| 识别号1 | 12 | 数据中心4 | 1 | 0 | 无循环 |
| 识别号2 | 10 | IDB1 | 1 | 2 | 新循环 (10-2)=8 |
| 识别号2 | 10 | IDB1 | 1 | 2 | (8-2) = 6 停止 |
我想做一个循环,将影响和概率相乘,直到获得所需值(例如 6),然后停止循环,直到达到 6。但再次开始 ID2 上的循环...等等,任何建议?
我认为它必须是这样的:
while (df['问题'] - df['影响']*df['影响'] < 6): df['循环'] = res
循环应创建“Res_Problem”列
AHashMap<Integer, Integer>有 10 个条目,但我只想打印 3 个条目。
代码:
HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
hm.put(2, 1);
hm.put(5, 3);
hm.put(7, 2);
hm.put(4, 1);
hm.put(6, 3);
hm.put(8, 2);
hm.put(9, 1);
hm.put(3, 3);
hm.put(1, 2);
hm.put(0, 2);
Iterator <Map.Entry<Integer, Integer>> itr = hm.entrySet().iterator();
int n=4;
int i=0;
while(itr.hasNext()){
if(i<n){
Map.Entry<Integer, Integer> entry = itr.next();
System.out.println(entry.getKey()+" repeated "+entry.getValue());
}
i++;
}
Run Code Online (Sandbox Code Playgroud)
输出
0 repeated 2
1 repeated 2
2 repeated 1
3 repeated 3 //program will wait for 2 or 3 seconds here
4 …Run Code Online (Sandbox Code Playgroud)