我喜欢读取日志文件并将其拆分为4个标量.
这是日志文件示例:
[time1] [error1] [who is1] mess is here1
[time2] [error2] mess is here2
Run Code Online (Sandbox Code Playgroud)
并喜欢得到那些标量:
($time, $err, $who, $mess)=('time1', 'error1', 'who is1', 'mess is here1')
($time, $err, $who, $mess)=('time2', 'error2', '', 'mess is here2')
Run Code Online (Sandbox Code Playgroud)
如何在perl中做到这一点?
我的代码就像它,但它不起作用:
while (<MYFILE>) {
chomp;
($time, $err, $who, $mess)=($_ =~/\[([.]*)\] \[([.]*)\] (\[([.]*)\]|[ ])([.]*)/);
$logi.= "<tr><td>$time</td><td>$err</td><td>$who</td><td>$mess</td></tr>\n";
}
Run Code Online (Sandbox Code Playgroud) 打印到stderr的原始代码:
extern "C" {
/* error: output error message */
void Error(const int error, char *message, ...)
{
va_list arg;
fflush(stdout);
fflush(stderr);
if (error > 0)
fprintf(stderr, "\nError: ");
else
fprintf(stderr, "\nWarning: ");
va_start(arg, message);
vfprintf(stderr, message, arg);
va_end(arg);
fflush(stderr);
if (error > 0)
exit(error);
}
void main(){
Error(0,"Problem %s in file", "sometext");
}
}//extern "C"
Run Code Online (Sandbox Code Playgroud)
我修改了我的代码看起来像那样.它应该打印到logcat
extern "C" {
#include <android/log.h>
#include <jni.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
/* error: output error message */ …Run Code Online (Sandbox Code Playgroud) 我有onItemClick监听器,我想使用id值.但它与位置具有相同的价值.
public void onItemClick(AdapterView<?> a, View view, int position, long id) {
DBh.something(id);
}
Run Code Online (Sandbox Code Playgroud)
我使用自定义ArrayAdapter类似于那个: onItemClickListener与自定义适配器和列表视图
我试图使用row.setId()但其int不长.