我的Perl程序正在从通过USB连接的串行设备读取数据.我在伪Perl中的脚本标题:
use warnings;
use strict;
use Device::SerialPort;
my $PortObj = tie( *$handle , "Device::SerialPort" , $PortName ) or die "Cannot open serial port: $!\n";
while ( 1 ) {
my $readLength = read( $handle , my $frameData , $frameLength )
}
Run Code Online (Sandbox Code Playgroud)
一切正常,甚至当我从USB上拔下设备时,我能够从那种情况中恢复,当设备文件消失并重新出现时.我可以捕获从我自己的脚本中生成的所有错误,但加载的模块(Device :: SerialPort)也会产生警告,我不希望它们出现在我的日志记录中.
我可以在代码中添加某种标志,所以我没有看到这些特定的警告吗?对我来说重要的是只抑制来自模块的警告,而不是来自我自己脚本的警告.目前它看起来像这样:
[/dev/ttyUSB1] 0x0020 : 00 00 00 00 00 00 00 00 00 AA 93 82 73 68 5E 58 : ............sh^X [/dev/ttyUSB1] 0x0030 : 55 54 52 52 4F 4E 50 51 50 00 00 …
检查以下代码:
#include <avr/io.h>
const uint16_t baudrate = 9600;
void setupUART( void ) {
uint16_t ubrr = ( ( F_CPU / ( 16 * (float) baudrate ) ) - 1 + .5 );
UBRRH = ubrr >> 8;
UBRRL = ubrr & 0xff;
}
int main( void ) {
setupUART();
}
Run Code Online (Sandbox Code Playgroud)
这是用于编译代码的命令:
avr-gcc -g -DF_CPU=4000000 -Wall -Os -Werror -Wextra -mmcu=attiny2313 -Wa,-ahlmns=project.lst -c -o project.o project.cpp
Run Code Online (Sandbox Code Playgroud)
ubrr由编译器计算为25,到目前为止一直很好.但是,为了检查编译器计算的内容,我查看了反汇编列表.
000000ae <setupUART()>:
ae: 12 b8 out UBRRH, r1 ; 0x02
b0: 89 e1 ldi …Run Code Online (Sandbox Code Playgroud) 使用Perl正则表达式将字符串切成可用的部分时,我需要匹配除某个模式之外的所有内容.我在Perl Monks上发现这个提示后解决了它:
/^(?:(?!PATTERN).)*$/; # Matches strings not containing PATTERN
Run Code Online (Sandbox Code Playgroud)
虽然我解决了我最初的问题,但我对它的实际工作方式一无所知.我检查了perlre,但它有点太正式无法掌握.
正则表达式匹配不包含单词的行?有很多理解,但为什么.在我的例子和?:外括号如何工作?
有人可以打破正则表达式并用简单的词语解释它是如何工作的吗?
我花了我的周末编程一个小愚人节的笑话,但它不能按我想要的方式工作.
我有一个基于Drupal 6的网站,我希望尽可能少地改变它.这个想法是,从/ files目录提供的所有图像都被重定向到外部网络服务器(myserver),它将图像颠倒翻转,然后将其提供给浏览器.
为了使Drupal网站(targetserver)将所有图像请求重定向到另一台服务器,我设置了一个.htaccess,如下所示:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !^aprilFool$
RewriteRule ^(.*)$ http://myserver/aprilFool/?url=http://targetserver/files/$1 [R=302,L]
Run Code Online (Sandbox Code Playgroud)
到目前为止它很棒!当我启用所有内容时,愚人节的诡计会改变一些图像,并在客户端的浏览器中显示.
但是当我禁用.htaccess @targetserver时,我的浏览器拒绝意识到它只是一个临时的笑话而忘记了编辑过的图像:(
这是myserver/aprilFool上的Perl脚本的一个小节:
my $ua = LWP::UserAgent->new;
# Identify ourselves through the useragent, to prevent endless redirect loops
$ua->agent( 'aprilFool' );
# Load remote file
my $response = $ua->get( $url );
if ( $response->is_error ) { die "Cannot retrieve document $url\n"; }
my $imageData = $response->content;
# Determine the file's mime type, need that to determine if we want to change it or …Run Code Online (Sandbox Code Playgroud) 我正在查询文档的Web服务器,我想捕获文档和相关的服务器响应头(特别是Content-Type:...).我无法找到如何阅读标题.以下是我的Perl脚本中的一些代码片段,为了清楚起见,我留下了错误检查:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent( 'requiredCustomUserAgent' ); # I'm required to set a custom user agent
$imageData = $response->content; # This is the received document
Run Code Online (Sandbox Code Playgroud)
所以此时我可以检索Web文档,但我想知道服务器使用它发送的Content-Type.不幸的是,这并不总是与bash'file'命令找到的mime类型相同.在.js或.css文档的情况下,此文件方法失败.
我试图围绕这个安全编码示例中发生的事情.
我重写了代码以更好地支持我的问题:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my $prompt = 'name%n'; # The bad coding practice from the exercise.
my $password = 'badpass';
my $is_ok = ($password eq "goodpass");
print Dumper( $is_ok );
print "\n$prompt: Password ok? $is_ok\n";
print Dumper( $is_ok );
$is_ok = ($password eq "goodpass");
printf "\n$prompt: Password ok? %d\n" , $is_ok;
print Dumper( $is_ok );
Run Code Online (Sandbox Code Playgroud)
当我执行脚本时,输出如下:
$ ./authenticate.pl
$VAR1 = '';
name%n: Password ok?
$VAR1 = '';
Missing argument in printf at ./authenticate.pl …Run Code Online (Sandbox Code Playgroud) 以下程序的目的是定期输出串行数据帧.周期由定时中断定义,每秒一次.
该代码适用于Arduino IDE版本0022,但在1.0上我无法使其正常工作.使用定时器例程并maxFrameLength设置为0x40或更高时,控制器会锁定.使用0x39或更低时,程序继续运行(由闪烁的LED指示).
这里出了什么问题,为什么?这是一个错误吗?难道我做错了什么?
我正在使用http://code.google.com/p/arduino-timerone/downloads/detail?name=TimerOne-v9.zip作为Mega1280上的计时器例程.
#include "TimerOne.h"
#define LED 13
#define maxFrameLength 0x40
boolean stateLED = true;
byte frame[ maxFrameLength ];
void sendFrame() {
digitalWrite( LED , stateLED );
stateLED = !stateLED;
Serial.write( frame, maxFrameLength ); // ptr + bytes to send
}
void setup() {
pinMode( LED , OUTPUT );
Timer1.initialize( 1000000 ); // initialize timer1 with 1 second period
Timer1.attachInterrupt( sendFrame );
Serial.begin( 9600 );
};
void loop() {
};
Run Code Online (Sandbox Code Playgroud) 我有以下命令行在Linux命令提示符下工作:
vi /tmp/test.txt -s <( echo ":1 s/^\/\/ VERSION: .*$/\/\/VERSION: $(date)/g" )
Run Code Online (Sandbox Code Playgroud)
它创建一个包含以下vim命令的临时文件(使用Process Substitution):
:1 s/^\/\/ VERSION: .*$/\/\/ VERSION: $(date)/g
Run Code Online (Sandbox Code Playgroud)
它打开文件/tmp/test.txt进行编辑,并从先前创建的临时文件中执行命令.它找到第1行并用当前时间戳替换该行.看起来有点像这样:
// VERSION: Fri Apr 12 21:20:03 CEST 2013
...
...
Run Code Online (Sandbox Code Playgroud)
接下来我可以进行任何所需的编辑,只有当我决定保存文件时,所有更改都将提交到磁盘.首先更改磁盘上的文件,然后启动编辑器不是一个选项,因为文件将具有不同的时间戳,而内容本身不会更改.
到目前为止,它按设计/预期工作.
现在我正在尝试将此vi命令行移动到make文件中,这就是我失败的地方.我尝试了一个$(shell .....)结构,但是make会给我带来错误.
edit:
$(shell vi $(src).cpp -s <( echo ":1 s/^\/\/ VERSION: .*$/\/\/VERSION: $(date)/g" )
Run Code Online (Sandbox Code Playgroud)
我正在试图弄清楚Makefile中的行应如何阅读摆弄额外的引号和括号,但我还没有解决它.
我正在运行Ubuntu Linux 12.10和GNU Make 3.81
vi project.cpp -s <( echo ":1 s/^\/\/ VERSION: .*$/\/\/VERSION: $(date)/g" )Make似乎不喜欢"过程替代"结构<( command ).我不想使用额外的(真实)文件.
€ make edit
vi …Run Code Online (Sandbox Code Playgroud) 我在下面编写了一个小bash脚本,它按预期工作,但我添加了几个注释和换行符,以便于阅读,从而破坏了代码.删除注释和换行符应该使其成为有效的脚本.
### read all measurements from the database and list each value only once
sqlite3 -init /tmp/timeout /tmp/testje.sqlite \
'select distinct measurement from errors order by measurement;' |
### remove the first line of stdout as this is a notification rather than intended output
sed '1d' |
### loop though all found values
while read error; do
### count the number of occurences in the original table and print that
sqlite3 -init /tmp/timeout /tmp/testje.sqlite \
"select $error,count( measurement ) from …Run Code Online (Sandbox Code Playgroud) 我正在尝试从源代码构建 ddar( https://github.com/basak/ddar )。这些是我发出的命令:
sudo apt-get install devscripts python-protobuf debhelper python-all-dev python-support xmltoman python-setuptools
git clone https://github.com/basak/ddar.git
debuild -i -us -uc -b
Run Code Online (Sandbox Code Playgroud)
我的目标是安装 ddar 二进制文件,但我不知道出了什么问题。以下是最后几行debuild -i -us -uc -b:
dh_installdeb
dh_gencontrol
dpkg-gencontrol: warning: Provides field of package ddar: unknown substitution variable ${python:Provides}
dh_md5sums
dh_builddeb
dpkg-deb: warning: 'debian/ddar/DEBIAN/control' contains user-defined field 'Python-Version'
dpkg-deb: warning: ignoring 1 warning about the control file(s)
dpkg-deb: building package `ddar' in `../ddar_0.1-1_amd64.deb'.
dpkg-genchanges -b >../ddar_0.1-1_amd64.changes
dpkg-genchanges: binary-only upload - not including any source code …Run Code Online (Sandbox Code Playgroud)