我想使用这样的宏参数:
#define D(cond,...) do{ \
#if cond \
#define YYY 1 \
#else \
#define YYY 0 \
} while(0)
Run Code Online (Sandbox Code Playgroud)
是否可以?
UPD
也许当源将被预处理两次时:gcc -E source.c | gcc -xc -下一步将起作用:
#define D(cond,...) #define YYY cond&DEBUG
#if YYY
#define D(...) printf( __VA_ARGS__ )
#else
#define D(...)
#endif
Run Code Online (Sandbox Code Playgroud) 我想更好地理解typeglobs并编写小程序:
use Symbol;
open F, '>', \my $var;
t( F );
t( \F );
t( *F );
t( \*F );
sub t {
my $fh = shift;
print ">>$fh<<" . ref( $fh ) ."\n";
}
Run Code Online (Sandbox Code Playgroud)
输出是:
>>F<<
>>SCALAR(0x1e67fc8)<<SCALAR
>>*main::F<<
>>GLOB(0x1e53150)<<GLOB
Run Code Online (Sandbox Code Playgroud)
为什么GLOB仅在最后一种情况下被返回?
git am我正在运行上面的错误.手工比较我没有看到任何问题.有人可以指出错误在哪里吗?
$ git am 0012-Do-not-die-when-something-nasty-happen-in-the-comman.patch --reject
Applying: Do not die when something nasty happen in the command
Checking patch lib/Devel/DebugHooks/CmdProcessor.pm...
error: while searching for:
return 0 unless $cmd && exists $DB::commands->{ $cmd };
# The command also should return defined value to keep interaction
if( defined (my $result = $DB::commands->{ $cmd }( $args_str )) ) {
return $result unless ref $result;
# Allow commands to evaluate $expr at a debugged script context
error: patch failed: lib/Devel/DebugHooks/CmdProcessor.pm:14
Applying patch …Run Code Online (Sandbox Code Playgroud) 当我使用命令查看日志树时
git log --graph --decorate --pretty=oneline --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
我看到下一条日志消息:
* 5bfe287 Squashed commit of the following:
Run Code Online (Sandbox Code Playgroud)
是否有一个选项可以--expand-squash将此类提交视为分支?
git log --graph --decorate --pretty=oneline --abbrev-commit --expand-squash
* 5bfe287 Squashed commit of the following:
|\
| * b10cbf5 Do not debug befer/after DB:: actions
| * 453e963 Debug debugger: implemented tescase for returning from debugger
|/
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
$headers;
some_sub( %$headers );
Run Code Online (Sandbox Code Playgroud)
当我打电话时,some_sub我得到一个错误:
不能使用未定义的值作为HASH参考...
但类似的代码不会产生错误:
$headers->{ x };
Run Code Online (Sandbox Code Playgroud)
为什么自动复制在第一个示例中的工作方式与在第二个示例中的工作方式不同?
UPD
我注意到@ThisSuitIsBlackNot.我真的问:
为什么我的$ h; $ h - > {foo}的作品和我的$ h; %$ h没有
UPD
真正的代码:
my $email = Email::Simple->create(()
,header => [()
,To => $address
,From => $cnf->{ from }
,Subject => $subject
,'Content-Type' => 'text/html; charset="utf8"'
,%$headers
]
,body => $body
);
Run Code Online (Sandbox Code Playgroud) 我有这样的布局:
@@ layouts/v2.html.ep
<html lang="en">
<head>
%= content_for 'stylesheets'
</head>
<body>
%= include 'layouts/v2/header'
<main class="main">
%= include 'layouts/v2/menu'
<div class="content">
%= content
</div>
</main>
</body>
</html>
@@ layouts/v2/menu
% content_for stylesheets => begin
%= stylesheet 'v2/css/menu.css'
% end
<aside class="menu">
...
</aside>
@@ layouts/v2/header
% content_for stylesheets => begin
%= stylesheet 'v2/css/header.css'
% end
<header class="header">
...
</header>
Run Code Online (Sandbox Code Playgroud)
这里当包含模板时,我包括他们的样式表.在模板中注意这一点:
% content_for stylesheets => begin
%= stylesheet 'v2/css/menu.css'
% end
Run Code Online (Sandbox Code Playgroud)
但是这样做太晚了,因为<head>已经渲染了.
解决这个问题,我可以%= content_for 'stylesheets'从<head>页面的底部移动.但我希望首先加载样式表. …
当我这样做时,git push --force我会看到下一个输出git:
$ git push --force
Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 2.36 KiB | 1.18 MiB/s, done.
Total 21 (delta 14), reused 0 (delta 0)
To repo:/v1/repos/DB-Hooks
+ 7b4eaa2...1295174 reimplement -> reimplement (forced update)
$ git log --graph --decorate --pretty=oneline --abbrev-commit 7b4eaa2...1295174
* 1295174 (HEAD -> reimplement) TEMPORARY
* 0f477bf Prettify code
* 09630ef Setup $DB::single
* 7b4eaa2 TEMPORARY
Run Code Online (Sandbox Code Playgroud)
如何从此日志中查看此处发生的情况? …
shift
将数组的第一个值移开并返回...
这样做是为了速度优化并避免按值复制.
也在perlsub
数组@_是一个本地数组,但它的元素是实际标量参数的别名.特别是,如果更新元素$ _ [0],则更新相应的参数
因此,如果我们my $self = shift在sub中执行,我们将第一个值移位@_,这是一个别名,不是吗?
但是当我们比较这两个时:
sub test {
print \$_[0]; # SCALAR(0xf73c38)
my $x = shift;
print \$x; # SCALAR(0xf79800)
}
Run Code Online (Sandbox Code Playgroud)
我们看到那$x是副本.
为什么shift@_ 的ed值不是别名?
因此,如果也为案例复制了价值my $x = shift,它会提供什么好处my $x = $_[0]呢?
我有错误:
Ambiguous call resolved as CORE::join(), qualify as such or use & at
Run Code Online (Sandbox Code Playgroud)
当我修复错误时:
$args = CORE::join( ', ', @$args );
Run Code Online (Sandbox Code Playgroud)
一切正常.
但当我把它修复为:
$args = &join( ', ', @$args );
Run Code Online (Sandbox Code Playgroud)
正如错误消息所示,我得到了不同的错误:
Can't locate object method "_make_instance" via package ", " (perhaps you forgot to load ", "?) at
Run Code Online (Sandbox Code Playgroud)
为什么第二次修复不起作用?
use strict;
use warnings;
sub XX { 30 };
my $rnd = 3;
my $z = -XX * $rnd;
Run Code Online (Sandbox Code Playgroud)
给出错误: Can't use string ("3") as a symbol ref while "strict refs" in use
这无济于事:
my $z = -XX * ($rnd);
Run Code Online (Sandbox Code Playgroud)
我收到下一个错误:
Scalar found where operator expected at game4.pl line 7, near "* ($rnd"
(Missing operator before $rnd?)
syntax error at game4.pl line 7, near "* ($rnd"
Execution of game4.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
如何强制EXPR而不是GLOB取消引用?
perl ×6
git ×3
c ×1
filehandle ×1
git-am ×1
git-push ×1
macros ×1
mojolicious ×1
patch ×1
perl-core ×1
ref ×1
reference ×1
subroutine ×1
typeglob ×1